Class CacheFilter

java.lang.Object
com.levigo.jadice.web.server.filter.CacheFilter
All Implemented Interfaces:
jakarta.servlet.Filter

@WebFilter(description="Enable caching for cacheable GWT resources", displayName="jadice web toolkit GWT resource caching", filterName="jwtCacheFilter", urlPatterns="/*", asyncSupported=true) public class CacheFilter extends Object implements jakarta.servlet.Filter
This Filter adds the required HTTP Headers to the to the HttpServletResponse to allow the browser to cache the requested resource. By default this filter is applied to GWT's *.cache.* files. If any of these resources is requested the filter will inject the following HTTP headers into the response:
  • Cache-Control: public, max-age=cacheExpirySeconds
  • Expires: System.currentTimeMillis() + cacheExpirySeconds * 1000
  • Pragma will be deleted, if existing
cacheExpirySeconds is a configurable value that can be set through the filter initialization parameter "cache-expiry-seconds". If the initialization parameter is omitted the default value 15552000L (180 days) will be used instead.
  • Field Details

  • Constructor Details

    • CacheFilter

      public CacheFilter()
      Default constructor.
    • CacheFilter

      public CacheFilter(String... additionalPatterns)
      Constructs a filter instance with additional patterns.
      Parameters:
      additionalPatterns - regular expressions
  • Method Details

    • init

      public void init(jakarta.servlet.FilterConfig filterConfig) throws jakarta.servlet.ServletException
      Specified by:
      init in interface jakarta.servlet.Filter
      Throws:
      jakarta.servlet.ServletException
    • doFilter

      public void doFilter(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response, jakarta.servlet.FilterChain chain) throws IOException, jakarta.servlet.ServletException
      Specified by:
      doFilter in interface jakarta.servlet.Filter
      Throws:
      IOException
      jakarta.servlet.ServletException
    • appliesTo

      protected boolean appliesTo(String path)
      Checks whether this filter applies to the given path.
      Parameters:
      path - path of the requested resource
      Returns:
      true if one of the patterns matches the given path
    • destroy

      public void destroy()
      Specified by:
      destroy in interface jakarta.servlet.Filter