ehcache]]>

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

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.PageFragmentCachingFilter
              extended by net.sf.ehcache.constructs.web.filter.SimplePageFragmentCachingFilter
All Implemented Interfaces:
javax.servlet.Filter

public class SimplePageFragmentCachingFilter
extends PageFragmentCachingFilter

A simple page fragment CachingFilter suitable for most uses.

It uses a Singleton CacheManager created with the default factory method. Override to use a different CacheManager

The meaning of page fragment is:

For full page see SimplePageCachingFilter.

Keys

Pages are cached based on their key. The key for this cache is the URI followed by the query string. An example is /admin/SomePage.jsp?id=1234&name=Beagle.

This key technique is suitable for a wide range of uses. It is independent of hostname and port number, so will work well in situations where there are multiple domains which get the same content, or where users access based on different port numbers.

A problem can occur with tracking software, where unique ids are inserted into request query strings. Because each request generates a unique key, there will never be a cache hit. For these situations it is better to parse the request parameters and override calculateKey(javax.servlet.http.HttpServletRequest) with an implementation that takes account of only the significant ones.

Configuring Caching with ehcache

A cache entry in ehcache.xml should be configured with the name NAME.

Cache attributes including expiry are configured per cache name. To specify a different behaviour simply subclass, specify a new name and create a separate cache entry for it.

Gzipping

Page fragments should never be gzipped.

Page fragments are stored in the cache ungzipped.

Version:
$Id: SimplePageFragmentCachingFilter.java 512 2007-07-10 09:18:45Z gregluck $
Author:
Greg Luck

Field Summary
static java.lang.String NAME
          This filter's name
 
Fields inherited from class net.sf.ehcache.constructs.web.filter.CachingFilter
blockingCache
 
Fields inherited from class net.sf.ehcache.constructs.web.filter.Filter
exceptionsToLogDifferently, exceptionsToLogDifferentlyLevel, filterConfig, NO_FILTER, suppressStackTraces
 
Constructor Summary
SimplePageFragmentCachingFilter()
           
 
Method Summary
protected  java.lang.String calculateKey(javax.servlet.http.HttpServletRequest httpRequest)
          CachingFilter works off a key.
protected  CacheManager getCacheManager()
          Gets the CacheManager for this CachingFilter.
protected  java.lang.String getCacheName()
          Returns the name of the cache to use for this filter.
 
Methods inherited from class net.sf.ehcache.constructs.web.filter.PageFragmentCachingFilter
buildPage, doFilter, writeResponse
 
Methods inherited from class net.sf.ehcache.constructs.web.filter.CachingFilter
buildPageInfo, checkNoReentry, doDestroy, doInit, setContentType, setCookies, setHeaders, setStatus, writeContent, writeResponse
 
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

NAME

public static final java.lang.String NAME
This filter's name

See Also:
Constant Field Values
Constructor Detail

SimplePageFragmentCachingFilter

public SimplePageFragmentCachingFilter()
Method Detail

calculateKey

protected java.lang.String calculateKey(javax.servlet.http.HttpServletRequest httpRequest)
CachingFilter works off a key.

This test implementation has a single key.

Specified by:
calculateKey in class CachingFilter
Parameters:
httpRequest -
Returns:
the key, generally the URL plus request parameters

getCacheManager

protected CacheManager getCacheManager()
Gets the CacheManager for this CachingFilter. It is therefore up to subclasses what CacheManager to use.

This method was introduced in ehcache 1.2.1. Older versions used a singleton CacheManager instance created with the default factory method.

Specified by:
getCacheManager in class CachingFilter
Returns:
the CacheManager to be used
Since:
1.2.1

getCacheName

protected java.lang.String getCacheName()
Returns the name of the cache to use for this filter.

Specified by:
getCacheName in class CachingFilter
Returns:
the name of the cache to use for this filter.

ehcache]]>