okhttp / okhttp3 / CacheControl

CacheControl

class CacheControl

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 7234, 5.2.

Types

Builder

class Builder

Builds a Cache-Control request header.

Properties

isPrivate

val isPrivate: Boolean

isPublic

val isPublic: Boolean

Functions

immutable

fun immutable(): Boolean

maxAgeSeconds

fun maxAgeSeconds(): Int

The duration past the response's served date that it can be served without validation.

maxStaleSeconds

fun maxStaleSeconds(): Int

minFreshSeconds

fun minFreshSeconds(): Int

mustRevalidate

fun mustRevalidate(): Boolean

noCache

fun noCache(): Boolean

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.

noStore

fun noStore(): Boolean

If true, this response should not be cached.

noTransform

fun noTransform(): Boolean

onlyIfCached

fun onlyIfCached(): Boolean

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.

sMaxAgeSeconds

fun sMaxAgeSeconds(): Int

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.

toString

fun toString(): String

Companion Object Properties

FORCE_CACHE

val FORCE_CACHE: CacheControl

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 a 504 Unsatisfiable Request.

FORCE_NETWORK

val FORCE_NETWORK: CacheControl

Cache control request directives that require network validation of responses. Note that such requests may be assisted by the cache via conditional GET requests.

Companion Object Functions

parse

fun parse(headers: Headers): CacheControl

Returns the cache directives of headers. This honors both Cache-Control and Pragma headers if they are present.