Package com.squareup.okhttp
Class CacheControl
- java.lang.Object
-
- com.squareup.okhttp.CacheControl
-
public final class CacheControl extends Object
A Cache-Control header with cache directives from a server or client. These directives set policy on what responses can be stored, and which requests can be satisfied by those stored responses.See RFC 2616, 14.9.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCacheControl.BuilderBuilds aCache-Controlrequest header.
-
Field Summary
Fields Modifier and Type Field Description static CacheControlFORCE_CACHECache control request directives that uses the cache only, even if the cached response is stale.static CacheControlFORCE_NETWORKCache control request directives that require network validation of responses.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisPrivate()booleanisPublic()intmaxAgeSeconds()The duration past the response's served date that it can be served without validation.intmaxStaleSeconds()intminFreshSeconds()booleanmustRevalidate()booleannoCache()In a response, this field's name "no-cache" is misleading.booleannoStore()If true, this response should not be cached.booleannoTransform()booleanonlyIfCached()This field's name "only-if-cached" is misleading.static CacheControlparse(Headers headers)Returns the cache directives ofheaders.intsMaxAgeSeconds()The "s-maxage" directive is the max age for shared caches.StringtoString()Returns a string containing a concise, human-readable description of this object.
-
-
-
Field Detail
-
FORCE_NETWORK
public static final CacheControl FORCE_NETWORK
Cache control request directives that require network validation of responses. Note that such requests may be assisted by the cache via conditional GET requests.
-
FORCE_CACHE
public static final CacheControl FORCE_CACHE
Cache control request directives that uses the cache only, even if the cached response is stale. If the response isn't available in the cache or requires server validation, the call will fail with a504 Unsatisfiable Request.
-
-
Method Detail
-
noCache
public boolean noCache()
In a response, this field's name "no-cache" is misleading. It doesn't prevent us from caching the response; it only means we have to validate the response with the origin server before returning it. We can do this with a conditional GET.In a request, it means do not use a cache to satisfy the request.
-
noStore
public boolean noStore()
If true, this response should not be cached.
-
maxAgeSeconds
public int maxAgeSeconds()
The duration past the response's served date that it can be served without validation.
-
sMaxAgeSeconds
public int sMaxAgeSeconds()
The "s-maxage" directive is the max age for shared caches. Not to be confused with "max-age" for non-shared caches, As in Firefox and Chrome, this directive is not honored by this cache.
-
isPrivate
public boolean isPrivate()
-
isPublic
public boolean isPublic()
-
mustRevalidate
public boolean mustRevalidate()
-
maxStaleSeconds
public int maxStaleSeconds()
-
minFreshSeconds
public int minFreshSeconds()
-
onlyIfCached
public boolean onlyIfCached()
This field's name "only-if-cached" is misleading. It actually means "do not use the network". It is set by a client who only wants to make a request if it can be fully satisfied by the cache. Cached responses that would require validation (ie. conditional gets) are not permitted if this header is set.
-
noTransform
public boolean noTransform()
-
parse
public static CacheControl parse(Headers headers)
Returns the cache directives ofheaders. This honors both Cache-Control and Pragma headers if they are present.
-
toString
public String toString()
Description copied from class:ObjectReturns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toStringmethod if you intend implementing your owntoStringmethod.
-
-