class ResourceCacheControl implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        // Check the request path and set the cache-control header if we find
        // it matches what we're looking for.
        if (request instanceof HttpServletRequest) {
            if (isCacheableResourceRequest((HttpServletRequest)request)) {
                HttpServletResponse httpServletResponse = (HttpServletResponse) response;

                //
                // Set the expiry to one year.
                //
                // Note that this does NOT mean that the browser will never send a request
                // for these resources. If you click reload in the browser (def in Chrome) it will
                // send an If-Modified-Since request to the server (at a minimum), which means you at
                // least have the request overhead even if it results in a 304 response. Setting the
                // Cache-Control header helps for normal browsing (clicking on links, bookmarks etc),
                // in which case the local cache is fully used (no If-Modified-Since requests for
                // non-stale resources).
                //
                httpServletResponse.setHeader("Cache-Control", "public, max-age=31536000");
                response = new HttpServletResponseWrapper(httpServletResponse) {
                    @Override
                    public void setHeader(String name, String value) {
                        // Block the setting of the legacy HTTP/1.0 "Expires" header.
                        // Note that, strictly speaking, this should not be required because
                        // the HTTP spec dictates that the Cache-Control header takes priority.
                        // Lets eliminate it anyway in case a browser/intermediary doesn't comply.
                        if (!name.equalsIgnoreCase("Expires")) {
                            super.setHeader(name, value);
                        }
                    }
                };
            }
        }
        // continue to execute the filer chain as normal
        chain.doFilter(request, response);
    }

      ResourceCacheControl();

}