net.sf.ehcache.constructs.web.filter
Class SimpleCachingHeadersPageCachingFilter
java.lang.Object
net.sf.ehcache.constructs.web.filter.Filter
net.sf.ehcache.constructs.web.filter.CachingFilter
net.sf.ehcache.constructs.web.filter.SimplePageCachingFilter
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. |
|
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.CachingFilter |
buildPageInfo, checkNoReentry, doDestroy, doFilter, doInit, setCacheNameIfAnyConfigured, setContentType, setCookies, setHeaders, setStatus, writeContent |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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
SimpleCachingHeadersPageCachingFilter
public SimpleCachingHeadersPageCachingFilter()
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:
- Last-Modified
- Expires
- Cache-Control
- ETag
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.