CacheFilter
The CacheFilter
manages a simple disk cache for
images, and ensures that:
-
Cached images are used if available
-
All requested and currently un-cached images are cached
If an incoming request has not already been identified as a section or
content item request, then the CacheFilter
checks the
publication's image cache for the requested file. If it finds the
requested image, then it returns the image file, terminating the filter
chain.
If it does not find the requested file in the image cache, then it calls the next filter in the filter chain. If that filter returns an image file, then it:
-
Adds the image to the cache
-
Returns the image
Cached images are never invalidated. This means that if an image is updated (a new version is uploaded or the original image is modified), the cached copy will not be updated. The only way to fix this problem is to physically remove the outdated copy from the cache.
The CacheFilter
needs to be configured
before the filters/servlets that is should filter
see the The web.xml File for
an example.
The CacheFilter
is configured in
WEB.XML
as follows:
<filter> <filter-name>CacheFilter</filter-name> <filter-class>com.escenic.presentation.servlet.multimedia.CacheFilter</filter-class> <init-param> <param-name>oncePerRequest</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>path</param-name> <param-value>/var/www/images</param-value> </init-param> <init-param> <param-name>cache-control</param-name> <param-value>private;max-age=2</param-value> </init-param> <init-param> <param-name>allowNonCachedUrls</param-name> <param-value>false</param-value> </init-param> </filter>
Configuration
oncePerRequest
-
If set to
true
, then the filter is only executed for the initial request. If set tofalse
, then the filter is executed for every request, which on some servers may mean that it is re-applied each time an include operation calls a new JSP file. path
-
The path of the image cache folder. If not specified, then the cache location is determined by
filePublicationRoot
.filePublicationRoot
is a server property, defined in theServerConfig.properties
file. The cache will by default be located underfilePublicationRoot
in a folder with the name publication-name/multimedia/dynamic
. cache-control
-
The HTTP Cache-Control header to included with images served by the Content Engine. If this parameter is not specified, then a default Cache-Control header of
public;max-age=60
is included. This default value will cause browsers to cache the images for 60 seconds. The Cache-Control header format is specified in http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9. allowNonCachedUrls
-
If set to
true
, this parameter will allow the CacheFilter to serve dynamic image versions even if the multimedia directory is read-only and the image version is not already available. This will mean a significant performance overhead, so the filter will log an error whenever the image version cannot be cached. By default this is not allowed, and the request will result in an exception.