|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.ehcache.constructs.web.filter.Filter
net.sf.ehcache.constructs.web.filter.CachingFilter
public abstract class CachingFilter
An abstract CachingFilter.
This class should be sub-classed for each page to be cached. The filters must be declared in the web.xml deployment descriptor. Then a mapping from a web resource, such as a JSP, Servlet or static resouce needs to be defined. Finally, a succession of mappings can be used to create a filter chain. See SRV.6 of the Servlet 2.3 specification for more details. Care should be taken not to define a filter chain such that the sameCachingFilter
class is reentered.
The CachingFilter
uses the BlockingCache
. It blocks until the thread which
did a get which results in a null does a put. If reentry happens a second get happens before the first put. The second
get could wait indefinitely. This situation is monitored and if it happens, an IllegalStateException will be thrown.
Field Summary | |
---|---|
protected BlockingCache |
blockingCache
The cache holding the web pages. |
Fields inherited from class net.sf.ehcache.constructs.web.filter.Filter |
---|
exceptionsToLogDifferently, exceptionsToLogDifferentlyLevel, filterConfig, NO_FILTER, suppressStackTraces |
Constructor Summary | |
---|---|
CachingFilter()
|
Method Summary | |
---|---|
protected PageInfo |
buildPage(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.FilterChain chain)
Builds the PageInfo object by passing the request along the filter chain |
protected PageInfo |
buildPageInfo(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.FilterChain chain)
Build page info either using the cache or building the page directly. |
protected abstract java.lang.String |
calculateKey(javax.servlet.http.HttpServletRequest httpRequest)
CachingFilter works off a key. |
protected void |
checkNoReentry(javax.servlet.http.HttpServletRequest httpRequest)
Check that this caching filter is not being reentered by the same recursively. |
protected void |
doDestroy()
Destroys the filter. |
protected void |
doFilter(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.FilterChain chain)
Performs the filtering for a request. |
void |
doInit()
Initialises blockingCache to use. |
protected abstract CacheManager |
getCacheManager()
Gets the CacheManager for this CachingFilter. |
protected abstract java.lang.String |
getCacheName()
A meaningful name representative of the JSP page being cached. |
protected void |
setContentType(javax.servlet.http.HttpServletResponse response,
PageInfo pageInfo)
Set the content type |
protected void |
setCookies(PageInfo pageInfo,
javax.servlet.http.HttpServletResponse response)
Set the serializableCookies |
protected void |
setHeaders(PageInfo pageInfo,
boolean requestAcceptsGzipEncoding,
javax.servlet.http.HttpServletResponse response)
Set the headers in the response object, excluding the Gzip header |
protected void |
setStatus(javax.servlet.http.HttpServletResponse response,
PageInfo pageInfo)
Status code |
protected void |
writeContent(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
PageInfo pageInfo)
Writes the response content. |
protected void |
writeResponse(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
PageInfo pageInfo)
Writes the response from a PageInfo object. |
Methods inherited from class net.sf.ehcache.constructs.web.filter.Filter |
---|
acceptsEncoding, acceptsGzipEncoding, destroy, doFilter, filterNotDisabled, getFilterConfig, init, logRequestHeaders |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected BlockingCache blockingCache
Constructor Detail |
---|
public CachingFilter()
Method Detail |
---|
public void doInit() throws CacheException
blockingCache.setTimeoutMillis(int timeout)
and takes effect immediately
for all new requests
doInit
in class Filter
CacheException
- The most likely cause is that a cache has not been
configured in ehcache's configuration file ehcache.xml for the filter nameprotected void doDestroy()
doDestroy
in class Filter
protected void doFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain) throws AlreadyGzippedException, AlreadyCommittedException, FilterNonReentrantException, LockTimeoutException, java.lang.Exception
doFilter
in class Filter
request
- response
- chain
-
AlreadyGzippedException
- if a double gzip is attempted
AlreadyCommittedException
- if the response was committed on the way in or the on the way back
FilterNonReentrantException
- if an attempt is made to reenter this filter in the same request.
LockTimeoutException
- if this request is waiting on another that is populating the cache entry
and timeouts while waiting. Only occurs if the BlockingCache has a timeout set.
java.lang.Exception
- for all other exceptions. They will be caught and logged in
Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
protected PageInfo buildPageInfo(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain) throws java.lang.Exception
java.lang.Exception
protected PageInfo buildPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain) throws AlreadyGzippedException, java.lang.Exception
request
- response
- chain
-
AlreadyGzippedException
- if an attempt is made to double gzip the body
java.lang.Exception
protected void writeResponse(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, PageInfo pageInfo) throws java.io.IOException, java.util.zip.DataFormatException, ResponseHeadersNotModifiableException
request
- response
- pageInfo
-
java.io.IOException
java.util.zip.DataFormatException
ResponseHeadersNotModifiableException
protected void setContentType(javax.servlet.http.HttpServletResponse response, PageInfo pageInfo)
response
- pageInfo
- protected void setCookies(PageInfo pageInfo, javax.servlet.http.HttpServletResponse response)
pageInfo
- response
- protected void setStatus(javax.servlet.http.HttpServletResponse response, PageInfo pageInfo)
response
- pageInfo
- protected void setHeaders(PageInfo pageInfo, boolean requestAcceptsGzipEncoding, javax.servlet.http.HttpServletResponse response)
pageInfo
- requestAcceptsGzipEncoding
- response
- protected abstract java.lang.String getCacheName()
protected abstract CacheManager getCacheManager()
protected abstract java.lang.String calculateKey(javax.servlet.http.HttpServletRequest httpRequest)
httpRequest
-
protected void writeContent(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, PageInfo pageInfo) throws java.io.IOException, ResponseHeadersNotModifiableException
response
- pageInfo
-
java.io.IOException
ResponseHeadersNotModifiableException
protected void checkNoReentry(javax.servlet.http.HttpServletRequest httpRequest) throws FilterNonReentrantException
httpRequest
-
FilterNonReentrantException
- if reentry is detected
|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |