info.magnolia.module.cache.filter
Class CacheHeadersFilter

java.lang.Object
  extended by info.magnolia.cms.filters.AbstractMgnlFilter
      extended by info.magnolia.module.cache.filter.CacheHeadersFilter
All Implemented Interfaces:
MgnlFilter, javax.servlet.Filter

public class CacheHeadersFilter
extends AbstractMgnlFilter

Filter that sets cache headers, allowing or dening cache at client-side. By default the filter adds the "Cache-Control: public" and expire directives to resources so that everything can be cached by the browser. Setting the nocache property to true has the opposite effect, forcing browsers to avoid caching.

The following example shows how to configure the filter so that static resources (images, css, js) gets cached by the browser, and deny cache for html pages.

 + server
    + filters
      + ...
      + headers-cache
        - class                  info.magnolia.module.cache.filter.CacheHeadersFilter
        - expirationMinutes      1440 (default)
        + bypasses
          + extensions
            - class              info.magnolia.voting.voters.ExtensionVoter
            - allow              gif,jpg,png,swf,css,js
            - not                true
      + headers-nocache
        - class                  info.magnolia.module.cache.filter.CacheHeadersFilter
        - nocache                true
        + bypasses
          + extensions
            - class              info.magnolia.voting.voters.ExtensionVoter
            - allow              html
            - not                true
 

Version:
$Id: $
Author:
Fabrizio Giustina

Constructor Summary
CacheHeadersFilter()
           
 
Method Summary
 void doFilter(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain)
           
 void setExpirationMinutes(long expirationMinutes)
          Sets the expirationMinutes.
 void setNocache(boolean nocache)
          Sets the nocache.
 
Methods inherited from class info.magnolia.cms.filters.AbstractMgnlFilter
acceptsEncoding, acceptsGzipEncoding, addAndVerifyHeader, addBypass, addMapping, bypasses, destroy, doFilter, getBypasses, getDispatching, getMapping, getMappings, getName, headerContains, init, isEnabled, mapsTo, matches, matchesDispatching, setDispatching, setEnabled, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheHeadersFilter

public CacheHeadersFilter()
Method Detail

setExpirationMinutes

public void setExpirationMinutes(long expirationMinutes)
Sets the expirationMinutes.

Parameters:
expirationMinutes - the expirationMinutes to set

setNocache

public void setNocache(boolean nocache)
Sets the nocache.

Parameters:
nocache - the nocache to set

doFilter

public void doFilter(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response,
                     javax.servlet.FilterChain chain)
              throws IOException,
                     javax.servlet.ServletException
Specified by:
doFilter in class AbstractMgnlFilter
Throws:
IOException
javax.servlet.ServletException


Copyright © 2003-2012 Magnolia International Ltd.. All Rights Reserved.