content: package alien4cloud.webconfiguration;
  
  import java.io.IOException;
  import java.util.concurrent.TimeUnit;
  
  import javax.servlet.Filter;
  import javax.servlet.FilterChain;
  import javax.servlet.FilterConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * This filter is used in production, to put HTTP cache headers with a long (1 month) expiration time.
   */
  public class CacheFilter implements Filter {
  
      // Cache period is 1 month (in ms)
      private final static long CACHE_PERIOD = TimeUnit.DAYS.toMillis(31L);
  
      // We consider the last modified date is the start up time of the server
      private final static long LAST_MODIFIED = System.currentTimeMillis();
  
      @Override
      public void init(FilterConfig filterConfig) throws ServletException {
          // Nothing to initialize
      }
  
      @Override
      public void destroy() {
          // Nothing to destroy
      }
  
      @Override
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
          HttpServletResponse httpResponse = (HttpServletResponse) response;
  
          httpResponse.setHeader("Cache-Control", "max-age=2678400000, public");
          httpResponse.setHeader("Pragma", "cache");
  
          // Setting Expires header, for proxy caching
          httpResponse.setDateHeader("Expires", CACHE_PERIOD + System.currentTimeMillis());
  
          // Setting the Last-Modified header, for browser caching
          httpResponse.setDateHeader("Last-Modified", LAST_MODIFIED);
  
          chain.doFilter(request, response);
      }
  }