tags:

views:

160

answers:

3

Jetty has a CacheControl parameter (can be specified webdefault.xml) that determines the caching behavior of clients (by affecting headers sent to clients).

Does Tomcat has a similar option? In short, I want to turn off caching of all pages delivered by a tomcat server and/or by a specific webapp?

Update

Please note that I am not referring to server-side caching. I want the server to tell all clients (browsers) not to use their own cache and to always fetch the content from the server. I want to do it for all resources, including static resources (.css, .js, etc.) at once.

+1  A: 

may be this what you are looking for :

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Context%20Parameters

    cachingAllowed : If the value of this flag is true, the cache for static

 resources will be used. If not specified, the default value of the flag is true.

Also delete the application cache folder in /work/Catalina/localhost after changing this flag.

daedlus
Thanks, but this does not help me. The parameter you're referring to affects server-side caching. I want the server to tell all clients (browsers) not to use their own cache and to always fetch the content from the server. And, I want to do it for all resources at once.
Itay
ah ok..afaik implementing a filter is one way of doing it.
daedlus
Seems like There is not built-in cache control in Tomcat.
daedlus
+1  A: 

I don't believe there is a configuration to do this. But it should not be much of an effort to write a filter to set the Cache-Control header on a per webapp-basis. E.g.:

public class test implements Filter {

        public void doFilter(ServletRequest request, ServletResponse response,
                        FilterChain chain) throws IOException, ServletException {

            chain.doFilter(request, response);
            ((StatusResponse)response).setHeader("Cache-Control", 
                                          "max-age=0, private, must-revalidate");
        }

        public void destroy() {
        }

        public void init(FilterConfig arg0) throws ServletException {
        }
}

And you'd place this snippet into your webapp's web.xml file.

<filter>
    <filter-name>SetCacheControl</filter-name>
    <filter-class>ch.dietpizza.cacheControlFilter</filter-class>
</filter>                       
<filter-mapping>
    <filter-name>SetCacheControl</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Stu Thompson
A: 

The only param I know of is disableProxyCaching on <Valve> elements. See here.

Sean Owen