This page last changed on Feb 23, 2007 by cholmes.

Caching with OSCache

GeoServer has a simple plugin that you can install that will set up server-side caching. The tool it uses is called OS Cache. For those seeking a pure java solution this works decently, but we're currently recommending TileCache as the preferred way to do GeoServer caching. See TileCache Tutorial for more information.

This page will guide you through setting it up. (note that this is for geoserver 1.4-RC1 and beyond).

Step 1: Download

Download this file.

Step 2: Install

Extract the contents of the file to your WEB-INF folder.

The contents of the zip-file are:

+ classes
  + oscache.properties
+ lib
  + oscache-2.3..2.jar
+ license.txt

When extracted, all files should be under WEB-INF:

+ WEB-INF
  + classes
    + oscache.properties
  + lib
    + oscache-2.3..2.jar
  + license.txt

Step 3: Configure

The last step is to set up your web.xml file.
Just copy and paste the below xml into your web.xml file:

<!-- OSCache configuration. Set time to -1 so the cached responses never expire. Scope should be application. -->
  <filter>
    <filter-name>CacheFilter</filter-name>
    <filter-class>com.opensymphony.oscache.web.filter.CacheFilter</filter-class>
    <init-param>
        <param-name>time</param-name>
        <param-value>-1</param-value>
    </init-param>
    <init-param>
        <param-name>scope</param-name>
        <param-value>application</param-value>
    </init-param>
  </filter>

  <!-- OSCache: cache the output of all WMS responses -->
  <filter-mapping>
      <filter-name>CacheFilter</filter-name>
      <url-pattern>/wms/*</url-pattern>
  </filter-mapping>

  <!-- OSCache: cache the output of all WFS responses -->
<!-- this is commented out for now as you usually don't benefit much from WFS caching -->
  <!--filter-mapping>
      <filter-name>CacheFilter</filter-name>
      <url-pattern>/wfs/*</url-pattern>
  </filter-mapping-->

Save the file and start up the server.

More configuration options are available in the oscache.properties file you extracted.

Step 4: Enable FeatureType Caching

Navigate to the FeatureType editor in the web admin GUI.
Select the feature type you would like to be cachable and hit the Edit button.

  1. Find the check box that says Enable Caching and make sure it is checked.
  2. In the field labeled Cache time enter a value in seconds that you would like other servers to cache the result for.
  3. Hit Submit
  4. Hit Apply and Save

That should be it!

Further reading

OSCache tutorial
How it uses servlet filters to cache
Cache filter configuration
Cache properties file config

Document generated by Confluence on Jan 16, 2008 23:27