Class CacheFilter
- All Implemented Interfaces:
jakarta.servlet.Filter
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 TypeMethodDescriptionvoidsetCharsets(String value) This is a comma separated charset mapping of the form:mimeType:charsetThis allows you to specify a character encoding for a given mimeType.voidsetExpires(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
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 thedefinition in yourweb.xmlfile. 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:3600here, but the container was configured to returnapplication/x-javascriptfor *.js (a common mimeType for javascript), then your expiry setting for *.js files would not apply. Note, because CacheFilter is aURIRegexFiltersubclass, you can finely control the affected URIs. For example, by default the framework mapsCacheFilterwith 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
This is a comma separated charset mapping of the form:mimeType:charsetThis 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 yourweb.xmlfile, 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-1For 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-8here, but the container was configured to returnapplication/x-javascriptfor *.js (a common mimeType for javascript), then your charset setting for *.js files would not apply.
-