Thursday, 17 July 2014

Enable caching in tomcat 7

Caching is technique of storing files for future use. In we take it in context of website performance, caching helps browser to store different resources from server in local storage. Whenever a user request for resource browser first checks it cache and if it is available the resource is served from cache. This reduces network bandwidth and increases performance of your website. ( how to speed up your website ) 

Tomcat 7 has inbuilt cache filtering functionality. It uses ExpiresFilter, that is a Java Servlet API port of Apache mod_expires. This filters sets the expires headers for the HTTP responses. Follow the steps to enable caching on your tomcat 7 server.

Modify your web.xml file by adding below code

    <param-name>ExpiresByType image</param-name>
    <param-value>access plus 10 minutes</param-value>
    <param-name>ExpiresByType text/css</param-name>
    <param-value>access plus 10 minutes</param-value>
    <param-name>ExpiresByType application/javascript</param-name>
    <param-value>access plus 10 minutes</param-value>


You can specify any numeric values in param-values. However you can change the time unit in terms of days, minutes hours etc. Various units can be
  • years
  • months
  • weeks
  • days
  • hours
  • minutes
  • seconds
For more reference and detailed description you can Follow link.

1 comment:

  1. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog.
    It is very nicely explained. Your article adds best knowledge to our Java Online Training from India.
    or learn thru Java Online Training from India Students.