net.sf.ehcache.constructs.web.filter
Class SimpleCachingHeadersPageCachingFilter

java.lang.Object
  extended by net.sf.ehcache.constructs.web.filter.Filter
      extended by net.sf.ehcache.constructs.web.filter.CachingFilter
          extended by net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter
              extended by net.sf.ehcache.constructs.web.filter.SimpleCachingHeadersPageCachingFilter
All Implemented Interfaces:
javax.servlet.Filter

public class SimpleCachingHeadersPageCachingFilter
extends SimplePageCachingFilter

This Filter extends SimplePageCachingFilter, adding support for the HTTP cache headers: ETag, Last-Modified and Expires.

Because browsers and other HTTP clients have the expiry information returned in the response headers, they do not even need to request the page again. Even once the local browser copy has expired, the browser will do a conditional GET.

So why would you ever want to use SimplePageCachingFilter, which does not set these headers? Because in some caching scenarios you may wish to remove a page before its natural expiry. Consider a scenario where a web page shows dynamic data. Under Ehcache the Element can be removed at any time. However if a browser is holding expiry information, those browsers will have to wait until the expiry time before getting updated. The caching in this scenario is more about defraying server load rather than minimising browser calls.

Author:
Craig Andrews, Greg Luck
See Also:
SimplePageCachingFilter

Field Summary
static String NAME
          The name of the filter.
 
Fields inherited from class net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter
DEFAULT_CACHE_NAME
 
Fields inherited from class net.sf.ehcache.constructs.web.filter.CachingFilter
blockingCache, cacheName
 
Fields inherited from class net.sf.ehcache.constructs.web.filter.Filter
exceptionsToLogDifferently, filterConfig, NO_FILTER, suppressStackTraces
 
Constructor Summary
SimpleCachingHeadersPageCachingFilter()
           
 
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  long calculateTimeToLiveMilliseconds()
          Get the time to live for a page, in milliseconds
protected  HttpDateFormatter getHttpDateFormatter()
           
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.SimplePageCachingFilter
calculateKey, getCacheManager, getCacheName
 
Methods inherited from class net.sf.ehcache.constructs.web.filter.CachingFilter
buildPageInfo, checkNoReentry, doDestroy, doFilter, doInit, setCacheNameIfAnyConfigured, setContentType, setCookies, setHeaders, setStatus, writeContent
 
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

NAME

public static final String NAME
The name of the filter. This should match a cache name in ehcache.xml

See Also:
Constant Field Values
Constructor Detail

SimpleCachingHeadersPageCachingFilter

public SimpleCachingHeadersPageCachingFilter()
Method Detail

buildPage

protected PageInfo buildPage(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response,
                             javax.servlet.FilterChain chain)
                      throws AlreadyGzippedException,
                             Exception
Builds the PageInfo object by passing the request along the filter chain

The following headers are set:

Any of these headers aleady set in the response are ignored, and new ones generated. To control your own caching headers, use SimplePageCachingFilter.

Overrides:
buildPage in class CachingFilter
Parameters:
request -
response -
chain -
Returns:
a Serializable value object for the page or page fragment
Throws:
AlreadyGzippedException - if an attempt is made to double gzip the body
Exception

getHttpDateFormatter

protected final HttpDateFormatter getHttpDateFormatter()
Returns:
A lazily created HttpDateFormatter instance scoped to this filter

writeResponse

protected void writeResponse(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response,
                             PageInfo pageInfo)
                      throws IOException,
                             DataFormatException,
                             ResponseHeadersNotModifiableException
Writes the response from a PageInfo object. This method actually performs the conditional GET and returns 304 if not modified, short-circuiting the normal writeResponse.

Indeed, if the short cicruit does not occur it calls the super method.

Overrides:
writeResponse in class CachingFilter
Throws:
IOException
DataFormatException
ResponseHeadersNotModifiableException

calculateTimeToLiveMilliseconds

protected long calculateTimeToLiveMilliseconds()
Get the time to live for a page, in milliseconds

Returns:
time to live in milliseconds


Copyright © 2003-2011 Terracotta, Inc.. All Rights Reserved.