Various code clean-up. No functional changes.

This commit is contained in:
Harald Kuhr
2011-03-02 17:26:17 +01:00
parent e75741ccd3
commit af7d5fa94a
8 changed files with 36 additions and 35 deletions

View File

@@ -67,7 +67,7 @@ public class CacheFilter extends GenericFilter {
public void init() throws ServletException {
FilterConfig config = getFilterConfig();
// Default don't delete cache files on exit (peristent cache)
// Default don't delete cache files on exit (persistent cache)
boolean deleteCacheOnExit = "TRUE".equalsIgnoreCase(config.getInitParameter("deleteCacheOnExit"));
// Default expiry time 10 minutes
@@ -76,6 +76,7 @@ public class CacheFilter extends GenericFilter {
String expiryTimeStr = config.getInitParameter("expiryTime");
if (!StringUtil.isEmpty(expiryTimeStr)) {
try {
// TODO: This is insane.. :-P Let the expiry time be in minutes or seconds..
expiryTime = Integer.parseInt(expiryTimeStr);
}
catch (NumberFormatException e) {
@@ -179,21 +180,21 @@ public class CacheFilter extends GenericFilter {
// TODO: Extract, complete and document this class, might be useful in other cases
// Maybe add it to the ServletUtil class
static class ServletContextLoggerAdapter extends Logger {
private final ServletContext mContext;
private final ServletContext context;
public ServletContextLoggerAdapter(String pName, ServletContext pContext) {
super(pName, null);
mContext = pContext;
context = pContext;
}
@Override
public void log(Level pLevel, String pMessage) {
mContext.log(pMessage);
context.log(pMessage);
}
@Override
public void log(Level pLevel, String pMessage, Throwable pThrowable) {
mContext.log(pMessage, pThrowable);
context.log(pMessage, pThrowable);
}
}
}

View File

@@ -69,7 +69,7 @@ class CacheResponseWrapper extends HttpServletResponseWrapper {
}
/*
NOTE: This class defers determining if a response is cachable until the
NOTE: This class defers determining if a response is cacheable until the
output stream is needed.
This it the reason for the somewhat complicated logic in the add/setHeader
methods below.
@@ -80,7 +80,7 @@ class CacheResponseWrapper extends HttpServletResponseWrapper {
cachedResponse = cached.createCachedResponse();
streamDelegate = new ServletResponseStreamDelegate(this) {
protected OutputStream createOutputStream() throws IOException {
// Test if this request is really cachable, otherwise,
// Test if this request is really cacheable, otherwise,
// just write through to underlying response, and don't cache
if (isCachable()) {
return cachedResponse.getOutputStream();

View File

@@ -35,10 +35,7 @@ import com.twelvemonkeys.util.LinkedMap;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* CachedResponseImpl
@@ -53,7 +50,7 @@ class CachedResponseImpl implements CachedResponse {
int status;
protected CachedResponseImpl() {
headers = new LinkedMap<String, List<String>>(); // Keep headers in insertion order
headers = new LinkedHashMap<String, List<String>>(); // Keep headers in insertion order
}
// For use by HTTPCache, when recreating CachedResponses from disk cache
@@ -82,7 +79,7 @@ class CachedResponseImpl implements CachedResponse {
continue;
}
// TODO: Replace Last-Modified with X-Cached-At? See CachedEntityImpl, line 50
// TODO: Replace Last-Modified with X-Cached-At? See CachedEntityImpl
String[] headerValues = getHeaderValues(header);
@@ -99,7 +96,7 @@ class CachedResponseImpl implements CachedResponse {
}
/**
* Writes the cahced content to the response
* Writes the cached content to the response
*
* @param pStream the response stream
* @throws java.io.IOException
@@ -132,6 +129,7 @@ class CachedResponseImpl implements CachedResponse {
*/
public String[] getHeaderValues(final String pHeaderName) {
List<String> values = headers.get(pHeaderName);
if (values == null) {
return null;
}
@@ -152,6 +150,7 @@ class CachedResponseImpl implements CachedResponse {
*/
public String getHeaderValue(final String pHeaderName) {
List<String> values = headers.get(pHeaderName);
return (values != null && values.size() > 0) ? values.get(0) : null;
}

View File

@@ -12,7 +12,7 @@ import java.io.OutputStream;
* @version $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-servlet/src/main/java/com/twelvemonkeys/servlet/cache/ClientCacheResponse.java#2 $
*/
public final class ClientCacheResponse extends AbstractCacheResponse {
// It's quite useless to cahce the data either on disk or in memory, as it already is cached in the client's cache...
// It's quite useless to cache the data either on disk or in memory, as it already is cached in the client's cache...
// It would be nice if we could bypass that...
public OutputStream getOutputStream() throws IOException {

View File

@@ -357,8 +357,7 @@ public class HTTPCache {
}
}
// else if (not cached ||<7C>stale), resolve through wrapped (caching) response
// else if (not cached || stale), resolve through wrapped (caching) response
// else render to response
// TODO: This is a bottleneck for uncachable resources. Should not