Package com.squareup.okhttp
Class CacheControl.Builder
- java.lang.Object
-
- com.squareup.okhttp.CacheControl.Builder
-
- Enclosing class:
- CacheControl
public static final class CacheControl.Builder extends Object
Builds aCache-Controlrequest header.
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CacheControlbuild()CacheControl.BuildermaxAge(int maxAge, TimeUnit timeUnit)Sets the maximum age of a cached response.CacheControl.BuildermaxStale(int maxStale, TimeUnit timeUnit)Accept cached responses that have exceeded their freshness lifetime by up tomaxStale.CacheControl.BuilderminFresh(int minFresh, TimeUnit timeUnit)Sets the minimum number of seconds that a response will continue to be fresh for.CacheControl.BuildernoCache()Don't accept an unvalidated cached response.CacheControl.BuildernoStore()Don't store the server's response in any cache.CacheControl.BuildernoTransform()Don't accept a transformed response.CacheControl.BuilderonlyIfCached()Only accept the response if it is in the cache.
-
-
-
Method Detail
-
noCache
public CacheControl.Builder noCache()
Don't accept an unvalidated cached response.
-
noStore
public CacheControl.Builder noStore()
Don't store the server's response in any cache.
-
maxAge
public CacheControl.Builder maxAge(int maxAge, TimeUnit timeUnit)
Sets the maximum age of a cached response. If the cache response's age exceedsmaxAge, it will not be used and a network request will be made.- Parameters:
maxAge- a non-negative integer. This is stored and transmitted withTimeUnit.SECONDSprecision; 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 tomaxStale. If unspecified, stale cache responses will not be used.- Parameters:
maxStale- a non-negative integer. This is stored and transmitted withTimeUnit.SECONDSprecision; 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 whenminFreshhave 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 withTimeUnit.SECONDSprecision; 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, a504 Unsatisfiable Requestresponse will be returned.
-
noTransform
public CacheControl.Builder noTransform()
Don't accept a transformed response.
-
build
public CacheControl build()
-
-