Tomcat: Cache-Control

前端 未结 6 704
悲哀的现实
悲哀的现实 2020-11-30 19:19

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

Does Tom

6条回答
  •  天命终不由人
    2020-11-30 19:57

    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.

    
        SetCacheControl
        ch.dietpizza.cacheControlFilter
                           
    
        SetCacheControl
        /*
    
    

提交回复
热议问题