How to change the time in Jahia cache for images?

  Written by The Jahia Team
 
Developers
Sysadmins
   Estimated reading time:
7.1.10
How to change the time in Jahia cache for images?

Answer

We recommend using a front-end server (apache, load-balancer) in order to modify this value in the HTTP header.

An alternative solution is to create the following path and to copy the below last-urlrewrite.xml file:
tomcat/webapps/ROOT/WEB-INF/classes/org/jahia/services/seo/urlrewrite/last-urlrewrite.xml
In this file, in the JCR files rule, you have to change the value of max-age=1 to the desired value.
In this case, the file overrides the one in the jahia-impl*.jar library.
In case (not really probable) that this file is modified in a future version of DXM, you should have to repeat this operation in order to have an up to date version of the last-urlrewrite.xml file.

last-urlrewrite.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
        "http://tuckey.org/res/dtds/urlrewrite3.2.dtd">

<urlrewrite>
    <!-- Client-side caching -->
    <rule>
        <name>Set no cache headers</name>
        <note>Resources that should not be cached</note>
        <condition type="attribute" name="jahiaCacheControlSet" operator="equal">^$</condition>
        <from>^/(welcome.*|start|validateTicket|administration.*|cms/.*|engines/.*\.jsp(\?.*)?|tools/.*|gwt/.*\.nocache\..*)$</from>
        <set type="response-header" name="Expires">Wed, 09 May 1979 05:30:00 GMT</set>
        <set type="response-header" name="Cache-Control">no-cache, no-store, must-revalidate, proxy-revalidate, max-age=0</set>
        <set type="response-header" name="Pragma">no-cache</set>
        <set type="request" name="jahiaCacheControlSet">done</set>
    </rule>
    <rule>
        <name>JCR files</name>
        <note>Do not set any cache expiration for JCR files</note>
        <condition type="attribute" name="jahiaCacheControlSet" operator="equal">^$</condition>
        <from>^/(files|repository)/.*$</from>
        <set type="response-header" name="Cache-Control">public, must-revalidate, max-age=1</set>
        <set type="request" name="jahiaCacheControlSet">done</set>
    </rule>
    <rule>
        <name>Set cache expires headers</name>
        <note>Cache all other resources by default</note>
        <condition type="header" name="Expires" operator="equal">^$</condition>
        <condition type="attribute" name="jahiaCacheControlSet" operator="equal">^$</condition>
        <set type="expires">1 month</set>
        <set type="response-header" name="Cache-Control">public, max-age=2678400</set>
        <set type="request" name="jahiaCacheControlSet">done</set>
    </rule>
    <!-- end of client-side caching -->
    <outbound-rule>
        <name>Append servername</name>
        <note>Check if we need to add server name</note>
        <condition type="attribute" name="jahiaSeoServernameForLink" operator="notequal">^$</condition>
        <from>^(.*)$</from>
        <to>%{attribute:jahiaSeoServernameForLink}$1</to>
    </outbound-rule>
</urlrewrite>