How to Configure Cache Control

Goal

Change the default setting for browser cache control in the embedded Jetty 9 web server.

Learn

Datameer comes with Jetty as embedded webservice, so follow the Rewrite Handler documentation.

Here are the necessary steps in detail:

1. Enter your Datameer installation directory.
2. Shut down Datameer service using bin/conductor.sh stop.
3. To check the current configuration, execute java -jar start.jar --list-config:

$ java -jar start.jar --list-config | grep -i 'etc/jetty*'
 ${jetty.base}/etc/jetty.xml
 ${jetty.base}/etc/jetty-http.xml
 ${jetty.base}/etc/jetty-deploy.xml
 ${jetty.base}/etc/jetty-plus.xml
 ${jetty.base}/etc/jetty-annotations.xml

4. The Jetty Active XMLs don't include the jetty-rewrite.xml module per default. To add the rewrite module, perform java -jar start.jar --add-to-start=rewrite.

$ java -jar start.jar --add-to-start=rewrite
INFO: rewrite         initialised in ${jetty.base}/start.ini (appended)
INFO: server          initialised in ${jetty.base}/start.ini
INFO: server          enabled in     ${jetty.base}/start.ini

5. Execute java -jar start.jar --list-config to verify that the module will be loaded at next start.

$ java -jar start.jar --list-config | grep -i 'ect/jetty-rewrite.xml'
 ${jetty.base}/etc/jetty-rewrite.xml

6. Edit etc/jetty-rewrite.xml and add the following rewrite rule:

<Ref refid="Rewrite">
<Call name="addRule">
<Arg>
<New class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">
<Set name="pattern">*</Set>
<Set name="name">Cache-Control</Set>
<Set name="value">Max-Age=0,public</Set>
<Set name="terminating">true</Set>
</New>
</Arg>
</Call>
</Ref>

7. Start Datameer service using bin/conductor.sh start.

Optional Steps

6.1 Adjust the URL pattern and value for Cache Control

Further Information

You will find further information under Managing Startup Modules, HTTP caching @ Google Developers, and Beginners Guide to HTTP Cache Headers