title: SpringMVC - How to clear cache only when user log out
body: <p>Currently I have the following filter that clear the cache for each request:</p>
  
  <pre><code>public class CacheControlFilter implements Filter {
  
      private static final Logger logger = Logger.getLogger(CacheControlFilter.class);
  
  
      @Override
      public void doFilter(ServletRequest request, ServletResponse response,
              FilterChain chain) throws IOException, ServletException {
  
          HttpServletResponse resp = (HttpServletResponse) response;
  
  
          resp.setDateHeader("Expires", 0);
          resp.setHeader("Last-Modified", new Date().toString());
          resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
          resp.setHeader("Pragma", "no-cache");
          resp.setHeader("X-Content-Type-Options", "nosniff");
          resp.setHeader("X-Frame-Options", "DENY");
          chain.doFilter(request, response);
      }
  </code></pre>
  
  <p>Please find logout method below:</p>
  
  <pre><code>  @RequestMapping(value = "/logout", method = RequestMethod.GET)
      public String logout(ModelMap model, HttpServletRequest request) {
  
      SecurityContextHolder.clearContext();
      request.getSession().invalidate();
  
  
      return Constants.LOGOUT;
  
      }
  </code></pre>
  
  <p>Is there a way to clear cache only when user log out instead of each request? I want to store my static files(css files,js files) in cache and clear it only when user log out</p>
  
  <p>Any advice is most welcome.</p>
  
  <p>Thanks</p>