Vapor Documentation Beta

Structure HTTPHeaders.​Cache​Control

public struct CacheControl

Represents the HTTP Cache-Control header.

Nested Types

HTTPHeaders.CacheControl.MaxStale

The max-stale option can be present with no value, or be present with a number of seconds. By using a struct you can check the nullability of the maxStale variable as well as then check the nullability of the seconds to differentiate.

Initializers

init(must​Revalidated:​no​Cache:​no​Store:​no​Transform:​is​Public:​is​Private:​proxy​Revalidate:​only​IfCached:​immutable:​max​Age:​sMax​Age:​max​Stale:​min​Fresh:​stale​While​Revalidate:​stale​IfError:​)

public init(mustRevalidated: Bool = false, noCache: Bool = false, noStore: Bool = false, noTransform: Bool = false, isPublic: Bool = false, isPrivate: Bool = false, proxyRevalidate: Bool = false, onlyIfCached: Bool = false, immutable: Bool = false, maxAge: Int? = nil, sMaxAge: Int? = nil, maxStale: MaxStale? = nil, minFresh: Int? = nil, staleWhileRevalidate: Int? = nil, staleIfError: Int? = nil)

Creates a new CacheControl.

Properties

must​Revalidate

var mustRevalidate: Bool

Indicates that once a resource becomes stale, caches must not use their stale copy without successful validation on the origin server.

no​Cache

var noCache: Bool

Caches must check with the origin server for validation before using the cached copy.

no​Store

var noStore: Bool

The cache should not store anything about the client request or server response.

no​Transform

var noTransform: Bool

No transformations or conversions should be made to the resource. The Content-Encoding, Content-Range, Content-Type headers must not be modified by a proxy. A non-transparent proxy or browser feature such as Google's Light Mode might, for example, convert between image formats in order to save cache space or to reduce the amount of traffic on a slow link. The no-transform directive disallows this.

is​Public

var isPublic: Bool

The response may be cached by any cache, even if the response is normally non-cacheable

is​Private

var isPrivate: Bool

The response is for a single user and must not be stored by a shared cache. A private cache (like the user's browser cache) may store the response.

proxy​Revalidate

var proxyRevalidate: Bool

Like must-revalidate, but only for shared caches (e.g., proxies). Ignored by private caches.

only​IfCached

var onlyIfCached: Bool

Indicates to not retrieve new data. This being the case, the server wishes the client to obtain a response only once and then cache. From this moment the client should keep releasing a cached copy and avoid contacting the origin-server to see if a newer copy exists.

immutable

var immutable: Bool

Indicates that the response body will not change over time.

The resource, if unexpired, is unchanged on the server and therefore the client should not send a conditional revalidation for it (e.g. If-None-Match or If-Modified-Since) to check for updates, even when the user explicitly refreshes the page. Clients that aren't aware of this extension must ignore them as per the HTTP specification. In Firefox, immutable is only honored on https:// transactions. For more information, see also this blog post.

max​Age

var maxAge: Int?

The maximum amount of time a resource is considered fresh. Unlike theExpires header, this directive is relative to the time of the request.

sMax​Age

var sMaxAge: Int?

Overrides max-age or the Expires header, but only for shared caches (e.g., proxies). Ignored by private caches.

max​Stale

var maxStale: MaxStale?

Indicates the client will accept a stale response. An optional value in seconds indicates the upper limit of staleness the client will accept.

min​Fresh

var minFresh: Int?

Indicates the client wants a response that will still be fresh for at least the specified number of seconds.

stale​While​Revalidate

var staleWhileRevalidate: Int?

Indicates the client will accept a stale response, while asynchronously checking in the background for a fresh one. The value indicates how long the client will accept a stale response.

stale​IfError

var staleIfError: Int?

Indicates the client will accept a stale response if the check for a fresh one fails. The value indicates how many seconds long the client will accept the stale response after the initial expiration.

Methods

parse(_:​)

public static func parse(_ value: String) -> CacheControl?

serialize()

public func serialize() -> String

Generates the header string for this instance.