net.sf.scmwebgui
Class AbstractCacheFilter

java.lang.Object
  extended by net.sf.scmwebgui.AbstractCacheFilter
All Implemented Interfaces:
javax.servlet.Filter
Direct Known Subclasses:
CacheFilter

public abstract class AbstractCacheFilter
extends java.lang.Object
implements javax.servlet.Filter

This class is a Servlet 2.3 filter that caches responses that match a given criteria. This abstract class must be extended to define shouldCache(HttpServletRequest), that chooses whether or not cache the response asociated to the incoming request

Author:
mikeshadow

Field Summary
static java.lang.String CACHE_CLEAN_PERIOD_INIT_PARAM
          Cache period to clean
static java.lang.String CACHE_DIRECTORY_INIT_PARAM
          Cache directory initialization parameter
static java.lang.String CACHE_TIME_OF_LIFE_INIT_PARAM
          Content lifetime in cache
protected  javax.servlet.ServletContext ctx
           
 
Constructor Summary
AbstractCacheFilter()
          Default constructor
 
Method Summary
 void destroy()
          Called by the servlet container when the app is being destroyed.
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          Determines applies the cache or not, depending on the user request and shouldCache(HttpServletRequest)
protected abstract  java.lang.String getCachedFilePath(RequestContext reqCtx)
          Subclasses must override this method to specify the mapping between context URIs and paths to cached files
 void init(javax.servlet.FilterConfig cfg)
          Initializes this filter
protected  void invalidateCache(java.lang.String path, boolean recursive)
          Invalidates cache
protected  void invalidateContentCache(java.lang.String path)
           
protected abstract  boolean shouldCache(javax.servlet.http.HttpServletRequest req)
          Subclases must override this method to define the criteria for caching the response, given a user request
protected abstract  boolean shouldRefresh(javax.servlet.http.HttpServletRequest req)
          Subclasses must override this method to return whether a cached request should be refreshed or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_DIRECTORY_INIT_PARAM

public static final java.lang.String CACHE_DIRECTORY_INIT_PARAM
Cache directory initialization parameter

See Also:
Constant Field Values

CACHE_CLEAN_PERIOD_INIT_PARAM

public static final java.lang.String CACHE_CLEAN_PERIOD_INIT_PARAM
Cache period to clean

See Also:
Constant Field Values

CACHE_TIME_OF_LIFE_INIT_PARAM

public static final java.lang.String CACHE_TIME_OF_LIFE_INIT_PARAM
Content lifetime in cache

See Also:
Constant Field Values

ctx

protected javax.servlet.ServletContext ctx
Constructor Detail

AbstractCacheFilter

public AbstractCacheFilter()
Default constructor

Method Detail

init

public void init(javax.servlet.FilterConfig cfg)
          throws javax.servlet.ServletException
Initializes this filter

Specified by:
init in interface javax.servlet.Filter
Parameters:
cfg -
Throws:
javax.servlet.ServletException

destroy

public void destroy()
Called by the servlet container when the app is being destroyed. Does nothing

Specified by:
destroy in interface javax.servlet.Filter

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Determines applies the cache or not, depending on the user request and shouldCache(HttpServletRequest)

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
request -
response -
chain -
Throws:
java.io.IOException
javax.servlet.ServletException

shouldRefresh

protected abstract boolean shouldRefresh(javax.servlet.http.HttpServletRequest req)
Subclasses must override this method to return whether a cached request should be refreshed or not.

Parameters:
req -
Returns:

invalidateCache

protected void invalidateCache(java.lang.String path,
                               boolean recursive)
Invalidates cache

Parameters:
path -

invalidateContentCache

protected void invalidateContentCache(java.lang.String path)

getCachedFilePath

protected abstract java.lang.String getCachedFilePath(RequestContext reqCtx)
Subclasses must override this method to specify the mapping between context URIs and paths to cached files

Parameters:
ctxURI -
Returns:

shouldCache

protected abstract boolean shouldCache(javax.servlet.http.HttpServletRequest req)
Subclases must override this method to define the criteria for caching the response, given a user request

Parameters:
req - The user request
Returns:
True to cache response, or false to not cache response and just chain request processing


Copyright null null. All Rights Reserved.