Java Components


Cache Filter

The Caching Filter is a JSP filter designed to cache requests for better performance. It is especially suited to caching pages which require much processing time and / or memory usage, such as converted images.

How to Use this Component


This filter relies on the following libraries:


To use this filter, you must include the .jar file (plus any dependencies) in the web application's classpath (either in WEB-INF/lib or in the server's lib folder). You must then add the following code to the web.xml file:



You should place this filter definition before any resources you want to be cached.


This module looks to the config parameter 'config' to specify the location of the configuration XML file, relative to /WEB-INF. If the config parameter is not set, it defaults to 'cache.xml'.

The cache.xml file specifies which persistence backings to use (both disk and memory backings are included in the cache module), what URLs to cache, and how long to cache them for. A sample configuration file is included below: <?xml version="1.0" encoding="UTF-8"?>
  <persistence-backing class-name="org.homeunix.thecave.moss.jsp.cache.persistence.impl.MemoryPersistence">
    <parameter name="item-count" value="2"/>
  <persistence-backing class-name="org.homeunix.thecave.moss.jsp.cache.persistence.impl.DiskPersistence">
   <parameter name="cache-path" value="/var/cache/moss"/>
  <cache-mapping pattern=".*images/.*" expiryTime="60000"/>
  <cache-mapping pattern=".*\.jsp" expiryTime="3600"/>
  <cache-mapping pattern=".*\.css" expiryTime="60"/>  
The cache mapping patterns are regular expressions, matched against the request URL. The patterns are matched in the order they appear in the file. The persistence backing parameters are both optional; the memory persistence defaults to 32, and the disk persistence defaults to '/tmp/ca.digitalcave.moss.jsp.cache'.