|
||||||||||
| 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 Page, FreeMarker page, Velocity page, 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.
The following init-params are supported:
| Field Summary | |
|---|---|
protected net.sf.ehcache.constructs.blocking.BlockingCache |
blockingCache
The cache holding the web pages. |
protected String |
cacheName
The cache name can be set through init parameters. |
| Fields inherited from class net.sf.ehcache.constructs.web.filter.Filter |
|---|
exceptionsToLogDifferently, 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 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(javax.servlet.FilterConfig filterConfig)
Initialises blockingCache to use. |
protected abstract net.sf.ehcache.CacheManager |
getCacheManager()
Gets the CacheManager for this CachingFilter. |
protected String |
getCacheName()
A meaningful name representative of the JSP page being cached. |
protected void |
setCacheNameIfAnyConfigured(javax.servlet.FilterConfig filterConfig)
Sets the cacheName from the filterConfig |
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, processInitParams |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected String cacheName
protected net.sf.ehcache.constructs.blocking.BlockingCache blockingCache
| Constructor Detail |
|---|
public CachingFilter()
| Method Detail |
|---|
public void doInit(javax.servlet.FilterConfig filterConfig)
throws net.sf.ehcache.CacheException
blockingCache.setTimeoutMillis(int timeout) and takes effect
immediately for all new requests
doInit in class FilterfilterConfig - this filter's configuration.
net.sf.ehcache.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 setCacheNameIfAnyConfigured(javax.servlet.FilterConfig filterConfig)
protected 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,
net.sf.ehcache.constructs.blocking.LockTimeoutException,
Exception
calculateKey(javax.servlet.http.HttpServletRequest)
By default this method will queue requests requesting the page response
for a given key until the first thread in the queue has completed. The
request which occurs when the page expires incurs the cost of waiting for
the downstream processing to return the respone.
The maximum time to wait can be configured by setting
setTimeoutMillis on the underlying
BlockingCache.
doFilter in class Filterrequest - 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.
net.sf.ehcache.constructs.blocking.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.
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 Exception
Exception
protected PageInfo buildPage(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
javax.servlet.FilterChain chain)
throws AlreadyGzippedException,
Exception
request - response - chain -
AlreadyGzippedException - if an attempt is made to double gzip the body
Exception
protected void writeResponse(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
PageInfo pageInfo)
throws IOException,
DataFormatException,
ResponseHeadersNotModifiableException
request - response - pageInfo -
IOException
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 String getCacheName()
cacheName field is be set by the doInit
method. Override to control the name used. The significance is that the
name is used to find a cache configuration in ehcache.xml
protected abstract net.sf.ehcache.CacheManager getCacheManager()
protected abstract String calculateKey(javax.servlet.http.HttpServletRequest httpRequest)
httpRequest -
protected void writeContent(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
PageInfo pageInfo)
throws IOException,
ResponseHeadersNotModifiableException
response - pageInfo -
IOException
ResponseHeadersNotModifiableException
protected void checkNoReentry(javax.servlet.http.HttpServletRequest httpRequest)
throws FilterNonReentrantException
httpRequest -
FilterNonReentrantException - if reentry is detected
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||