1

We have website running with tomcat and apache and wish to cache only specific jpg, gif images at apache level to reduce tomcat load.

Regarding CSS and Javascripts, all of them can be cached.

Upon deployment of changed images, css and javascripts it should load automatically.

I am trying to get this configuration but could not find any.. Can someone please share sample configuration?

It is very crucial for us to cache only specific images, and its urgent as well.

1 Answer 1

1

In tomcat application context.xml add :

disableCacheProxy="false" securePagesWithPragma="false"

Followed by any one of the below :

1.Use jsp :

  • Create a new jsp eg. "nocache.jsp" with the below content :

    <meta http-equiv="pragma" content="no-cache">  
    <meta http-equiv="Cache-Control" content="no-store">    <!-- HTTP 1.1 -->  
    <meta http-equiv="Expires" content="0">
    
  • Include this jsp in all jsp's which u dont want to cache as :

    <jsp:include page="../nocache.jsp" />

2.Use Filter :

  • Create a new Filter class - "CacheHeaderFilter" to handle classes which are NOT to be cached as below :

    public void doFilter( ServletRequest request, ServletResponse response,   FilterChain filterChain) throws IOException, ServletException {   
        HttpServletResponse httpResponse = (HttpServletResponse)response;  
        httpResponse.setHeader("Cache-Control","no-cache");
        httpResponse.setHeader("Pragma","no-cache");  
        httpResponse.setDateHeader ("Expires", 0);  
        filterChain.doFilter(request, response);  
    }
    
  • In app web.xml, configure this filter and specify the URL's which are NOT to be cached as below :

    <filter>
        <filter-name>CacheFilter</filter-name>
        <filter-class>com.org.CacheHeaderFilter</filter-class>
    </filter>  
    
    <filter-mapping>
        <filter-name>CacheFilter</filter-name>
        <url-pattern>*.action</url-pattern>
    </filter-mapping>`
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.