Module io.jooby

Class CacheControl

java.lang.Object
io.jooby.handler.CacheControl

public class CacheControl extends Object
Class allowing the fine tune the browser cache behavior for assets.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Constant for the max-age parameter, when set, the Cache-Control header is set to no-store, must-revalidate.
    static final int
    Constant for the max-age parameter, when set, no Cache-Control header is generated.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the default caching configuration for assets.
    long
    Returns the max-age header parameter value.
    boolean
    Returns whether e-tag support is enabled.
    boolean
    Returns whether the handling of If-Modified-Since header is enabled.
    Returns a caching configuration for disabling cache completely.
    setETag(boolean etag)
    Turn on/off e-tag support.
    setLastModified(boolean lastModified)
    Turn on/off handling of If-Modified-Since header.
    setMaxAge(long maxAge)
    Set cache-control header with the given max-age value.
    Set cache-control header with the given max-age value.
    Set cache-control header to no-store, must-revalidate, disables e-tag and If-Modified-Since header support.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • UNDEFINED

      public static final int UNDEFINED
      Constant for the max-age parameter, when set, no Cache-Control header is generated.
      See Also:
    • NO_CACHE

      public static final int NO_CACHE
      Constant for the max-age parameter, when set, the Cache-Control header is set to no-store, must-revalidate.
      See Also:
  • Constructor Details

    • CacheControl

      public CacheControl()
  • Method Details

    • isEtag

      public boolean isEtag()
      Returns whether e-tag support is enabled.
      Returns:
      true if enabled.
    • isLastModified

      public boolean isLastModified()
      Returns whether the handling of If-Modified-Since header is enabled.
      Returns:
      true if enabled.
    • getMaxAge

      public long getMaxAge()
      Returns the max-age header parameter value.
      Returns:
      the max-age header parameter value.
    • setETag

      public CacheControl setETag(boolean etag)
      Turn on/off e-tag support.
      Parameters:
      etag - True for turning on.
      Returns:
      This instance.
    • setLastModified

      public CacheControl setLastModified(boolean lastModified)
      Turn on/off handling of If-Modified-Since header.
      Parameters:
      lastModified - True for turning on. Default is: true.
      Returns:
      This instance.
    • setMaxAge

      public CacheControl setMaxAge(long maxAge)
      Set cache-control header with the given max-age value. If max-age is greater than 0.
      Parameters:
      maxAge - Max-age value in seconds.
      Returns:
      This instance.
      See Also:
    • setMaxAge

      public CacheControl setMaxAge(Duration maxAge)
      Set cache-control header with the given max-age value. If max-age is greater than 0.
      Parameters:
      maxAge - Max-age value in seconds.
      Returns:
      This instance.
    • setNoCache

      public CacheControl setNoCache()
      Set cache-control header to no-store, must-revalidate, disables e-tag and If-Modified-Since header support.
      Returns:
      This instance.
    • defaults

      public static CacheControl defaults()
      Returns the default caching configuration for assets.
      • e-tag support: enabled
      • If-Modified-Since support: enabled
      • max-age: UNDEFINED (no Cache-Control header is generated)
      Returns:
      the default cache configuration.
    • noCache

      public static CacheControl noCache()
      Returns a caching configuration for disabling cache completely.
      • e-tag support: disabled
      • If-Modified-Since support: disabled
      • max-age: NO_CACHE (the Cache-Control header is set to no-store, must-revalidate)
      Returns:
      cache configuration that disables caching.