Package com.twelvemonkeys.servlet.cache
Class HTTPCache
- java.lang.Object
-
- com.twelvemonkeys.servlet.cache.HTTPCache
-
public class HTTPCache extends java.lang.Object
A "simple" HTTP cache. - Use a mix of parameters and hashcode + lenght with fixed (max) lenght? (Hashcodes of Strings are constant). - Store full filenames in .vary, instead of just extension, and use short filenames? (and only one .vary per dir).- Version:
- $Id: HTTPCache.java#4 $
- Author:
- Harald Kuhr
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
FILE_EXT_HEADERS
The file extension for header files (".headers"
)protected static java.lang.String
FILE_EXT_VARY
The file extension for varation-info files (".vary"
)protected static java.lang.String
HEADER_CACHE_CONTROL
The HTTP header"Cache-Control"
protected static java.lang.String
HEADER_CACHED_TIME
HTTP extension header"X-Cached-At"
protected static java.lang.String
HEADER_CONTENT_TYPE
The HTTP header"Content-Type"
protected static java.lang.String
HEADER_DATE
The HTTP header"Date"
protected static java.lang.String
HEADER_ETAG
The HTTP header"ETag"
protected static java.lang.String
HEADER_EXPIRES
The HTTP header"Expires"
protected static java.lang.String
HEADER_IF_MODIFIED_SINCE
The HTTP header"If-Modified-Since"
protected static java.lang.String
HEADER_IF_NONE_MATCH
The HTTP header"If-None-Match"
protected static java.lang.String
HEADER_LAST_MODIFIED
The HTTP header"Last-Modified"
protected static java.lang.String
HEADER_PRAGMA
The HTTP header"Pragma"
protected static java.lang.String
HEADER_VARY
The HTTP header"Vary"
protected static java.lang.String
HEADER_WARNING
The HTTP header"Warning"
-
Constructor Summary
Constructors Modifier Constructor Description HTTPCache(java.io.File pTempFolder, long pDefaultCacheExpiryTime, int pMaxMemCacheSize, int pMaxCachedEntites, boolean pDeleteCacheOnExit)
Creates anHTTPCache
.protected
HTTPCache(java.io.File pTempFolder, long pDefaultCacheExpiryTime, int pMaxMemCacheSize, int pMaxCachedEntites, boolean pDeleteCacheOnExit, java.util.logging.Logger pLogger)
HTTPCache(java.lang.String pName, javax.servlet.ServletContext pContext, int pDefaultCacheExpiryTime, int pMaxMemCacheSize, int pMaxCachedEntites, boolean pDeleteCacheOnExit)
Deprecated.UseHTTPCache(File, long, int, int, boolean)
instead.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
doCached(CacheRequest pRequest, CacheResponse pResponse, ResponseResolver pResolver)
Looks up theCachedEntity
for the given request.protected java.io.File
getRealFile(CacheRequest pRequest)
Allows a server-side cache mechanism to peek at the real file.protected void
invalidate(CacheRequest pRequest)
java.lang.String
toString()
-
-
-
Field Detail
-
HEADER_CACHE_CONTROL
protected static final java.lang.String HEADER_CACHE_CONTROL
The HTTP header"Cache-Control"
- See Also:
- Constant Field Values
-
HEADER_CONTENT_TYPE
protected static final java.lang.String HEADER_CONTENT_TYPE
The HTTP header"Content-Type"
- See Also:
- Constant Field Values
-
HEADER_DATE
protected static final java.lang.String HEADER_DATE
The HTTP header"Date"
- See Also:
- Constant Field Values
-
HEADER_ETAG
protected static final java.lang.String HEADER_ETAG
The HTTP header"ETag"
- See Also:
- Constant Field Values
-
HEADER_EXPIRES
protected static final java.lang.String HEADER_EXPIRES
The HTTP header"Expires"
- See Also:
- Constant Field Values
-
HEADER_IF_MODIFIED_SINCE
protected static final java.lang.String HEADER_IF_MODIFIED_SINCE
The HTTP header"If-Modified-Since"
- See Also:
- Constant Field Values
-
HEADER_IF_NONE_MATCH
protected static final java.lang.String HEADER_IF_NONE_MATCH
The HTTP header"If-None-Match"
- See Also:
- Constant Field Values
-
HEADER_LAST_MODIFIED
protected static final java.lang.String HEADER_LAST_MODIFIED
The HTTP header"Last-Modified"
- See Also:
- Constant Field Values
-
HEADER_PRAGMA
protected static final java.lang.String HEADER_PRAGMA
The HTTP header"Pragma"
- See Also:
- Constant Field Values
-
HEADER_VARY
protected static final java.lang.String HEADER_VARY
The HTTP header"Vary"
- See Also:
- Constant Field Values
-
HEADER_WARNING
protected static final java.lang.String HEADER_WARNING
The HTTP header"Warning"
- See Also:
- Constant Field Values
-
HEADER_CACHED_TIME
protected static final java.lang.String HEADER_CACHED_TIME
HTTP extension header"X-Cached-At"
- See Also:
- Constant Field Values
-
FILE_EXT_HEADERS
protected static final java.lang.String FILE_EXT_HEADERS
The file extension for header files (".headers"
)- See Also:
- Constant Field Values
-
FILE_EXT_VARY
protected static final java.lang.String FILE_EXT_VARY
The file extension for varation-info files (".vary"
)- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HTTPCache
protected HTTPCache(java.io.File pTempFolder, long pDefaultCacheExpiryTime, int pMaxMemCacheSize, int pMaxCachedEntites, boolean pDeleteCacheOnExit, java.util.logging.Logger pLogger)
-
HTTPCache
public HTTPCache(java.io.File pTempFolder, long pDefaultCacheExpiryTime, int pMaxMemCacheSize, int pMaxCachedEntites, boolean pDeleteCacheOnExit)
Creates anHTTPCache
.- Parameters:
pTempFolder
- the temp folder for this cache.pDefaultCacheExpiryTime
- Default expiry time for cached entities,>= 0
pMaxMemCacheSize
- Maximum size of in-memory cache for content in bytes,>= 0
(0
means no in-memory cache)pMaxCachedEntites
- Maximum number of entities in cachepDeleteCacheOnExit
- specifies wether the file cache should be deleted when the application or VM shuts down- Throws:
java.lang.IllegalArgumentException
- ifpName
orpContext
isnull
or if any ofpDefaultCacheExpiryTime
,pMaxMemCacheSize
orpMaxCachedEntites
are negative, or if the directory as given in the context attribute"javax.servlet.context.tempdir"
does not exist, and cannot be created.
-
HTTPCache
public HTTPCache(java.lang.String pName, javax.servlet.ServletContext pContext, int pDefaultCacheExpiryTime, int pMaxMemCacheSize, int pMaxCachedEntites, boolean pDeleteCacheOnExit)
Deprecated.UseHTTPCache(File, long, int, int, boolean)
instead.Creates anHTTPCache
.- Parameters:
pName
- Name of this cache (should be unique per application). Used for temp folderpContext
- Servlet context for the application.pDefaultCacheExpiryTime
- Default expiry time for cached entities,>= 0
pMaxMemCacheSize
- Maximum size of in-memory cache for content in bytes,>= 0
(0
means no in-memory cache)pMaxCachedEntites
- Maximum number of entities in cachepDeleteCacheOnExit
- specifies wether the file cache should be deleted when the application or VM shuts down- Throws:
java.lang.IllegalArgumentException
- ifpName
orpContext
isnull
or if any ofpDefaultCacheExpiryTime
,pMaxMemCacheSize
orpMaxCachedEntites
are negative, or if the directory as given in the context attribute"javax.servlet.context.tempdir"
does not exist, and cannot be created.
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
doCached
public void doCached(CacheRequest pRequest, CacheResponse pResponse, ResponseResolver pResolver) throws java.io.IOException, CacheException
Looks up theCachedEntity
for the given request.- Parameters:
pRequest
- the requestpResponse
- the responsepResolver
- the resolver- Throws:
java.io.IOException
- if an I/O error occursCacheException
- if the cached entity can't be resolved for some reason
-
invalidate
protected void invalidate(CacheRequest pRequest)
-
getRealFile
protected java.io.File getRealFile(CacheRequest pRequest)
Allows a server-side cache mechanism to peek at the real file. Default implementation returnnull
.- Parameters:
pRequest
- the request- Returns:
null
, always
-
-