Exemplo n.º 1
0
 /**
  * Tell the browser to not cache.
  *
  * <p>This sets several headers to try to ensure that the page will not be cached. Not sure if
  * last modified matters -goliver
  *
  * @param response the HTTP response to which we will add headers.
  */
 @Override
 public void setNoCache(HttpServletResponse response) {
   long past = System.currentTimeMillis() - LONG_EXPIRE;
   response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache, no-store");
   response.setHeader(HttpHeaders.PRAGMA, "no-cache");
   response.setDateHeader(HttpHeaders.EXPIRES, past);
   response.setDateHeader(HttpHeaders.LAST_MODIFIED, past);
 }
Exemplo n.º 2
0
 /**
  * Sets cache timeout to a given value.
  *
  * <p>This sets several headers to try to ensure that the page will be cached for the given length
  * of time. Of note is the last-modified header, which is set to a day ago so that browsers
  * consider it to be safe.
  *
  * @param response the HTTP response to which we will add headers.
  * @param expiration timeout value in milliseconds.
  */
 @Override
 public void setCacheTimeout(HttpServletResponse response, long expiration) {
   long now = System.currentTimeMillis();
   response.setHeader(HttpHeaders.VARY, "Accept-Encoding");
   response.setHeader(
       HttpHeaders.CACHE_CONTROL, String.format("max-age=%s, public", expiration / 1000));
   response.setDateHeader(HttpHeaders.EXPIRES, now + expiration);
   response.setDateHeader(HttpHeaders.LAST_MODIFIED, now - SHORT_EXPIRE);
 }