|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.weborganic.bastille.cache.filter.CachingFilterBase org.weborganic.bastille.cache.filter.StaticCachingFilter
public final class StaticCachingFilter
A caching filter for static resources such as scripts, images, styles, etc..
This filter is designed to be used for URIs which map directly to a file on the server as it will check whether the file has been changed and update the cache accordingly. These resources are typically served by the default Servlet on the Web container.
This filter will automatically compress resources such as styles and scripts while leaving images uncompressed. This is done based on the media type of the resource.
If this use agent does not support GZip encoding, the resource is served uncompressed.
The key for each resource is the path component of the URI. The scheme, host port, query
string and fragment are ignored. The HTTP method is also ignored, so that GET
and POST
methods are equivalent.
Field Summary | |
---|---|
static String |
DEFAULT_CACHE_CONTROL
The default cache control to use. |
static String |
DEFAULT_CACHE_NAME
The default of the cache to use. |
static long |
DEFAULT_FILESIZE_THRESHOLD
The default file size threshold. |
Constructor Summary | |
---|---|
StaticCachingFilter()
|
Method Summary | |
---|---|
String |
calculateKey(javax.servlet.http.HttpServletRequest req)
Returns the key for this cache. |
void |
destroy()
|
CacheManager |
getCacheManager()
Returns the CacheManager for this caching filter. |
String |
getDefaultCacheName()
Returns the default name for the cache managed by the filter. |
CachedResource |
getResource(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
javax.servlet.FilterChain chain)
Get the requested resource either from the cache or by invoking the page directly. |
void |
init(javax.servlet.FilterConfig config)
Initialises blockingCache to use. |
boolean |
isCacheable(javax.servlet.http.HttpServletRequest req)
Always return true unless the "berlioz-cache" parameter is set to "false"
or the file is too large or does not exist. |
void |
writeResponse(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
CachedResource resource)
Writes the response from a PageInfo object. |
Methods inherited from class org.weborganic.bastille.cache.filter.CachingFilterBase |
---|
doFilter, doFilter, writeContent |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_CACHE_NAME
public static final String DEFAULT_CACHE_CONTROL
public static final long DEFAULT_FILESIZE_THRESHOLD
Beyond this files are not cached but served directly.
Constructor Detail |
---|
public StaticCachingFilter()
Method Detail |
---|
public CacheManager getCacheManager()
CachingFilter
getCacheManager
in interface CachingFilter
public String getDefaultCacheName()
CachingFilter
This method must not return null
.
getDefaultCacheName
in interface CachingFilter
public void init(javax.servlet.FilterConfig config) throws CacheException
CachingFilterBase
The BlockingCache created by this method does not have a lock timeout set.
A timeout can be appled using blockingCache.setTimeoutMillis(int timeout)
and
takes effect immediately for all new requests
init
in interface javax.servlet.Filter
init
in class CachingFilterBase
config
- this filter's configuration.
CacheException
- The most likely cause is that a cache has not been configured in ehcache's
configuration file ehcache.xml for the filter namepublic void destroy()
destroy
in interface javax.servlet.Filter
public CachedResource getResource(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException, CacheException
This method may invoke the rest of the filter chain.
getResource
in interface CachingFilter
req
- The HTTP servlet request.res
- The HTTP servlet response.chain
- The filter chain.
IOException
- Should an IO error occur
javax.servlet.ServletException
- For general errors or errors while invoking the filetr chain.
CacheException
- For caching-specific error.public boolean isCacheable(javax.servlet.http.HttpServletRequest req)
true
unless the "berlioz-cache" parameter is set to "false"
or the file is too large or does not exist.
Indicates whether the resource from the specified request can return a cached copy.
This method may be used to determine whether of not this filter should be used for the resource. Implementations may use this method to decide whether to bypass the filter and directly invoke the rest of the filter chain.
isCacheable
in interface CachingFilter
req
- The HTTP servlet request.
true
if the caching filter can use a cache;
false
to invoke the rest of the filter chain.public void writeResponse(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, CachedResource resource) throws IOException, javax.servlet.ServletException
This method actually performs the conditional GET and returns 304 if not modified, short-circuiting the normal response.
writeResponse
in interface CachingFilter
req
- The HTTP servlet request.res
- the HTTP servlet response.resource
- The cached resource build previously.
IOException
- For I/O errors only
javax.servlet.ServletException
- For all other errors.public String calculateKey(javax.servlet.http.HttpServletRequest req)
calculateKey
in interface CachingFilter
req
- the HTTP Servlet request.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |