Class CacheHeaders

java.lang.Object
com.google.gerrit.util.http.CacheHeaders

public class CacheHeaders extends Object
Utilities to manage HTTP caching directives in responses.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    hasCacheHeader(javax.servlet.http.HttpServletResponse res)
     
    static void
    setCacheable(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, long age, TimeUnit unit)
    Permit caching the response for up to the age specified.
    static void
    setCacheable(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, long age, TimeUnit unit, boolean mustRevalidate)
    Permit caching the response for up to the age specified.
    static void
    setCacheablePrivate(javax.servlet.http.HttpServletResponse res, long age, TimeUnit unit, boolean mustRevalidate)
    Allow the response to be cached only by the user-agent.
    static void
    setCacheablePublic(javax.servlet.http.HttpServletResponse res, long age, TimeUnit unit, boolean mustRevalidate)
    Allow the response to be cached by proxies and user-agents.
    static void
    setNotCacheable(javax.servlet.http.HttpServletResponse res)
    Do not cache the response, anywhere.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • setNotCacheable

      public static void setNotCacheable(javax.servlet.http.HttpServletResponse res)
      Do not cache the response, anywhere.
      Parameters:
      res - response being returned.
    • setCacheable

      public static void setCacheable(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, long age, TimeUnit unit)
      Permit caching the response for up to the age specified.

      If the request is on a secure connection (e.g. SSL) private caching is used. This allows the user-agent to cache the response, but requests intermediate proxies to not cache. This may offer better protection for Set-Cookie headers.

      If the request is on plaintext (insecure), public caching is used. This may allow an intermediate proxy to cache the response, including any Set-Cookie header that may have also been included.

      Parameters:
      req - current request.
      res - response being returned.
      age - how long the response can be cached.
      unit - time unit for age, usually TimeUnit.SECONDS.
    • setCacheable

      public static void setCacheable(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, long age, TimeUnit unit, boolean mustRevalidate)
      Permit caching the response for up to the age specified.

      If the request is on a secure connection (e.g. SSL) private caching is used. This allows the user-agent to cache the response, but requests intermediate proxies to not cache. This may offer better protection for Set-Cookie headers.

      If the request is on plaintext (insecure), public caching is used. This may allow an intermediate proxy to cache the response, including any Set-Cookie header that may have also been included.

      Parameters:
      req - current request.
      res - response being returned.
      age - how long the response can be cached.
      unit - time unit for age, usually TimeUnit.SECONDS.
      mustRevalidate - true if the client must validate the cached entity.
    • setCacheablePublic

      public static void setCacheablePublic(javax.servlet.http.HttpServletResponse res, long age, TimeUnit unit, boolean mustRevalidate)
      Allow the response to be cached by proxies and user-agents.

      If the response includes a Set-Cookie header the cookie may be cached by a proxy and returned to multiple browsers behind the same proxy. This is insecure for authenticated connections.

      Parameters:
      res - response being returned.
      age - how long the response can be cached.
      unit - time unit for age, usually TimeUnit.SECONDS.
      mustRevalidate - true if the client must validate the cached entity.
    • setCacheablePrivate

      public static void setCacheablePrivate(javax.servlet.http.HttpServletResponse res, long age, TimeUnit unit, boolean mustRevalidate)
      Allow the response to be cached only by the user-agent.
      Parameters:
      res - response being returned.
      age - how long the response can be cached.
      unit - time unit for age, usually TimeUnit.SECONDS.
      mustRevalidate - true if the client must validate the cached entity.
    • hasCacheHeader

      public static boolean hasCacheHeader(javax.servlet.http.HttpServletResponse res)