Save This Page
Home » oscache-2.4.1-full » com.opensymphony.oscache » web » filter » [javadoc | source]
com.opensymphony.oscache.web.filter
public class: CacheFilter [javadoc | source]
java.lang.Object
   com.opensymphony.oscache.web.filter.CacheFilter

All Implemented Interfaces:
    Filter, ICacheKeyProvider, ICacheGroupsProvider

CacheFilter is a filter that allows for server-side caching of post-processed servlet content.

It also gives great programatic control over refreshing, flushing and updating the cache.

Field Summary
public static final  String HEADER_LAST_MODIFIED     
public static final  String HEADER_CONTENT_TYPE     
public static final  String HEADER_CONTENT_ENCODING     
public static final  String HEADER_EXPIRES     
public static final  String HEADER_IF_MODIFIED_SINCE     
public static final  String HEADER_CACHE_CONTROL     
public static final  String HEADER_ACCEPT_ENCODING     
public static final  int FRAGMENT_AUTODETECT     
public static final  int FRAGMENT_NO     
public static final  int FRAGMENT_YES     
public static final  int NOCACHE_OFF     
public static final  int NOCACHE_SESSION_ID_IN_URL     
public static final  long LAST_MODIFIED_OFF     
public static final  long LAST_MODIFIED_ON     
public static final  long LAST_MODIFIED_INITIAL     
public static final  long EXPIRES_OFF     
public static final  long EXPIRES_ON     
public static final  long EXPIRES_TIME     
public static final  long MAX_AGE_NO_INIT     
public static final  long MAX_AGE_TIME     
Method from com.opensymphony.oscache.web.filter.CacheFilter Summary:
acceptsGZipEncoding,   createCacheGroups,   createCacheKey,   destroy,   doFilter,   getCacheControlMaxAge,   getCacheGroupsProvider,   getCacheKeyProvider,   getCacheScope,   getCron,   getDisableCacheOnMethods,   getExpires,   getExpiresRefreshPolicy,   getFragment,   getLastModified,   getNocache,   getTime,   init,   isCacheable,   isCacheable,   isFilteredBefore,   isFragment,   setCacheControlMaxAge,   setCacheGroupsProvider,   setCacheKeyProvider,   setCacheScope,   setCron,   setDisableCacheOnMethods,   setExpires,   setExpiresRefreshPolicy,   setFragment,   setLastModified,   setNocache,   setTime
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.opensymphony.oscache.web.filter.CacheFilter Detail:
 public boolean acceptsGZipEncoding(HttpServletRequest request) 
    Check if the client browser support gzip compression.
 public String[] createCacheGroups(HttpServletRequest httpRequest,
    ServletCacheAdministrator scAdmin,
    Cache cache) 
 public String createCacheKey(HttpServletRequest httpRequest,
    ServletCacheAdministrator scAdmin,
    Cache cache) 
 public  void destroy() 
    Filter clean-up
 public  void doFilter(ServletRequest request,
    ServletResponse response,
    FilterChain chain) throws IOException, ServletException 
    The doFilter call caches the response by wrapping the HttpServletResponse object so that the output stream can be caught. This works by splitting off the output stream into two with the SplitServletOutputStream class. One stream gets written out to the response as normal, the other is fed into a byte array inside a ResponseContent object.
 public long getCacheControlMaxAge() 
 public ICacheGroupsProvider getCacheGroupsProvider() 
 public ICacheKeyProvider getCacheKeyProvider() 
 public int getCacheScope() 
    Returns PageContext.APPLICATION_SCOPE or PageContext.SESSION_SCOPE.
 public String getCron() 
 public List getDisableCacheOnMethods() 
 public long getExpires() 
 public EntryRefreshPolicy getExpiresRefreshPolicy() 
 public int getFragment() 
 public long getLastModified() 
 public int getNocache() 
 public int getTime() 
 public  void init(FilterConfig filterConfig) 
    Initialize the filter. This retrieves a ServletCacheAdministrator instance and configures the filter based on any initialization parameters.

    The supported initialization parameters are:

    • oscache-properties-file - the properties file that contains the OSCache configuration options to be used by the Cache that this Filter should use.
 public boolean isCacheable(ServletRequest request) 
    isCacheable is a method allowing a subclass to decide if a request is cachable or not.
 public boolean isCacheable(CacheHttpServletResponseWrapper cacheResponse) 
    isCacheable is a method allowing subclass to decide if a response is cachable or not.
 public boolean isFilteredBefore(ServletRequest request) 
    Checks if the request was filtered before, so guarantees to be executed once per request. You can override this methods to define a more specific behaviour.
 public boolean isFragment(HttpServletRequest request) 
    Checks if the request is a fragment in a page. According to Java Servlet API 2.2 (8.2.1 Dispatching Requests, Included Request Parameters), when a servlet is being used from within an include, the attribute javax.servlet.include.request_uri is set. According to Java Servlet API 2.3 this is excepted for servlets obtained by using the getNamedDispatcher method.
 public  void setCacheControlMaxAge(long cacheControlMaxAge) 
    max-age - defines the cache control response header max-age. Acceptable values are MAX_AGE_NO_INIT for don't initializing the max-age cache control, MAX_AGE_TIME the max-age information will be based on the time parameter and creation time of the content (expiration timestamp minus current timestamp), and [positive integer] value constant in seconds to be set in every response, the default value is 60.
 public  void setCacheGroupsProvider(ICacheGroupsProvider cacheGroupsProvider) 
    ICacheGroupsProvider - Class implementing the interface ICacheGroupsProvider. A developer can implement a method which provides cache groups based on the request, the servlect cache administrator and cache. The parameter has to be not null.
 public  void setCacheKeyProvider(ICacheKeyProvider cacheKeyProvider) 
    ICacheKeyProvider - Class implementing the interface ICacheKeyProvider. A developer can implement a method which provides cache keys based on the request, the servlect cache administrator and cache. The parameter has to be not null.
 public  void setCacheScope(int cacheScope) 
    scope - the default scope to cache content. Acceptable values are PageContext.APPLICATION_SCOPE (default) and PageContext.SESSION_SCOPE.
 public  void setCron(String cron) 
    cron - defines an expression that determines when the page content will expire. This allows content to be expired at particular dates and/or times, rather than once a cache entry reaches a certain age.
 public  void setDisableCacheOnMethods(List disableCacheOnMethods) 
    disableCacheOnMethods - Defines the http method name for which cacheing should be disabled. The default value is null for cacheing all requests without regarding the method name.
 public  void setExpires(long expires) 
    expires - defines if the expires header will be sent in the response. Acceptable values are EXPIRES_OFF for don't sending the header, even it is set in the filter chain, EXPIRES_ON (default) for sending it if it is set in the filter chain and EXPIRES_TIME the expires information will be intialized based on the time parameter and creation time of the content.
 public  void setExpiresRefreshPolicy(EntryRefreshPolicy expiresRefreshPolicy) 
    EntryRefreshPolicy - Class implementing the interface EntryRefreshPolicy. A developer can implement a class which provides a different custom cache invalidation policy for a specific cache entry. If not specified, the default policy is timed entry expiry as specified with the time parameter described above.
 public  void setFragment(int fragment) 
    fragment - defines if this filter handles fragments of a page. Acceptable values are FRAGMENT_AUTODETECT (default) for auto detect, FRAGMENT_NO and FRAGMENT_YES.
 public  void setLastModified(long lastModified) 
    lastModified - defines if the last modified header will be sent in the response. Acceptable values are LAST_MODIFIED_OFF for don't sending the header, even it is set in the filter chain, LAST_MODIFIED_ON for sending it if it is set in the filter chain and LAST_MODIFIED_INITIAL (default) the last modified information will be set based on the current time and changes are allowed.
 public  void setNocache(int nocache) 
    nocache - defines which objects shouldn't be cached. Acceptable values are NOCACHE_OFF (default) and NOCACHE_SESSION_ID_IN_URL if the session id is contained in the URL.
 public  void setTime(int time) 
    time - the default time (in seconds) to cache content for. The default value is 3600 seconds (one hour). Specifying -1 (indefinite expiry) as the cache time will ensure a content does not become stale until it is either explicitly flushed or the expires refresh policy causes the entry to expire.