HTTP caching and the Java EE API

Java EE doesn't define a dedicated API (or specification) for HTTP caching, but it provides a few helpers.

The more direct (and low level) way to configure it is by using the Servlet specification, which abstracts the HTTP layer:

public class NoStoreFilter implements Filter {    @Override    public void doFilter(ServletRequest request, ServletResponse    response, FilterChain filterChain)            throws IOException, ServletException {        final HttpServletResponse httpResponse =        HttpServletResponse.class.cast(response);        httpResponse.setHeader("Cache-Control", "no-store");        filterChain.doFilter(request, response);    }}

With this filter, the Cache-Control value will prevent the cached data from being persistently stored. To activate ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.