Skip to content

Instantly share code, notes, and snippets.

@alexandreaquiles
Created February 6, 2014 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexandreaquiles/8849163 to your computer and use it in GitHub Desktop.
Save alexandreaquiles/8849163 to your computer and use it in GitHub Desktop.
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class CacheBustingFilter implements Filter {
private static final String CACHE_CONTROL = "Cache-Control";
private static final String CACHE_SETTINGS = "must-revalidate,no-cache,no-store";
@Override
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (response instanceof HttpServletResponse) {
final HttpServletResponse resp = (HttpServletResponse) response;
resp.setHeader(CACHE_CONTROL, CACHE_SETTINGS);
}
chain.doFilter(request, response);
}
@Override
public void destroy() {}
@Override
public void init(FilterConfig filterConfig) throws ServletException {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment