How to Configure Cache Control


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


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/ stop.
3. To check the current configuration, execute java -jar start.jar --list-config:

$ java -jar start.jar --list-config | grep -i 'etc/jetty*'

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'

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

<Ref refid="Rewrite">
<Call name="addRule">
<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>

7. Start Datameer service using bin/ 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