Class CacheControl.Builder

  • Enclosing class:
    CacheControl

    public static final class CacheControl.Builder
    extends Object
    Builds a Cache-Control request header.
    • Constructor Detail

      • Builder

        public Builder()
    • Method Detail

      • maxAge

        public CacheControl.Builder maxAge​(int maxAge,
                                           TimeUnit timeUnit)
        Sets the maximum age of a cached response. If the cache response's age exceeds maxAge, it will not be used and a network request will be made.
        Parameters:
        maxAge - a non-negative integer. This is stored and transmitted with TimeUnit.SECONDS precision; finer precision will be lost.
      • maxStale

        public CacheControl.Builder maxStale​(int maxStale,
                                             TimeUnit timeUnit)
        Accept cached responses that have exceeded their freshness lifetime by up to maxStale. If unspecified, stale cache responses will not be used.
        Parameters:
        maxStale - a non-negative integer. This is stored and transmitted with TimeUnit.SECONDS precision; finer precision will be lost.
      • minFresh

        public CacheControl.Builder minFresh​(int minFresh,
                                             TimeUnit timeUnit)
        Sets the minimum number of seconds that a response will continue to be fresh for. If the response will be stale when minFresh have elapsed, the cached response will not be used and a network request will be made.
        Parameters:
        minFresh - a non-negative integer. This is stored and transmitted with TimeUnit.SECONDS precision; finer precision will be lost.
      • onlyIfCached

        public CacheControl.Builder onlyIfCached()
        Only accept the response if it is in the cache. If the response isn't cached, a 504 Unsatisfiable Request response will be returned.