Package com.isomorphic.servlet

# Class CacheFilter

java.lang.Object
com.isomorphic.servlet.BaseFilter
com.isomorphic.servlet.URIRegexFilter
com.isomorphic.servlet.CacheFilter

All Implemented Interfaces:
  `jakarta.servlet.Filter`

public class CacheFilter extends URIRegexFilter
A `URIRegexFilter` subclass with similar functionality to the `FileDownload` servlet - it serves files with configurable cacheing directives to minimize network traffic. However, because it is a `URIRegexFilter` subclass, you have fine control over affected URIs by use of regular expression matching. Additionally, if the file does not exist on disk, `chain.doFilter()` is called. This allows servlets to sit behind this filter and still work, in the common case that a URI is resolved by a servlet rather than pointing at an actual file

- ## Field Summary

  ### Fields inherited from class com.isomorphic.servlet.URIRegexFilter

  `matchURI, rules, rulesFile, uriCacheSize, useURICache`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `setCharsets(String value)`
  This is a comma separated charset mapping of the form: `mimeType:charset` This allows you to specify a character encoding for a given mimeType.
  `void`
  `setExpires(String value)`
  This is a comma separated expiration mapping of the form: `mimeType:seconds to expiry`.

  ### Methods inherited from class com.isomorphic.servlet.URIRegexFilter

  `matchedRule`

- ## Method Details

  - ### setExpires

    public void setExpires(String value)
    This is a comma separated expiration mapping of the form: `mimeType:seconds to expiry`. This allows you to specify how long, in seconds, the browser is allowed to cache a file matching a given mime type, from the time the file is originally served. You can set it by calling this method, but it is more common to specify init params on the `` definition in your `web.xml` file. For example, to set javascript files to expire in 1 hour and gif images to expire in 1 day:

         <filter>
             <filter-name>CacheFilterExpiry</filter-name>
             <filter-class>com.isomorphic.servlet.CacheFilter</filter-class>
             <init-param>
               <param-name>expires</param-name>
               <param-value>text/javascript:3600,image/gif:86400</param-value>
             </init-param>
         </filter>
         <filter-mapping>
             <filter-name>CacheFilterExpiry</filter-name>
             <url-pattern>/*</url-pattern>
         </filter-mapping>

    The comparison is an exact match of the specified mimeType against what the container returns for the intercepted URL. So, for example, if you specified `text/javascript:3600` here, but the container was configured to return `application/x-javascript` for *.js (a common mimeType for javascript), then your expiry setting for *.js files would not apply. Note, because CacheFilter is a `URIRegexFilter` subclass, you can finely control the affected URIs. For example, by default the framework maps `CacheFilter` with the following config, to ensure that the configured expires headers only apply to SmartClient assets:

         <init-param>
             <param-name>rules</param-name>
             <param-value>
                 match:isc_version=
             </param-value>
         </init-param>

  - ### setCharsets

    public void setCharsets(String value)
    This is a comma separated charset mapping of the form: `mimeType:charset` This allows you to specify a character encoding for a given mimeType. You can set it by calling this method, or by specifying init params on the `<filter>` definition in your `web.xml` file, like so:

            <init-param>
                <param-name>charset</param-name>
                <param-value>*:utf-8</param-value>
            </init-param>

    For example, to set javascript files to be served with the UTF-8 encoding, set this value to: `text/javascript:UTF-8`. To set ALL files to use a given encoding, use "*" - for example, to set files to use ISO-8859-1, use: `*:ISO-8859-1`

    For mimeTypes that do not have a charset specified, no charset setting is applied, so the container default is used.

    The comparison is an exact match of the specified mimeType against what the container returns for the intercepted URL. So, for example, if you specified `text/javascript:UTF-8` here, but the container was configured to return `application/x-javascript` for *.js (a common mimeType for javascript), then your charset setting for *.js files would not apply.