pub struct CacheControl { /* private fields */ }
Expand description

Directives to limit cache lifetime, read from cache-control and kvarn-cache-control headers.

See Self::from_cache_control and Self::from_kvarn_cache_control for respective parsing.

Implementations

Respects max-age= and no-store parts of cache-control header.

Uses the standard syntax.

Errors

Can return CacheControlError::MultipleMaxAge and CacheControlError::InvalidInteger.

Converts a kvarn-cache-control header to a CacheControl directive.

The kvarn-cache-control header is used for reverse-proxy servers and other downstream sources to signal how Kvarn should cache their content. This header is prioritized over cache-control, but serves a similar function. This only applies to the server cache, whereas cache-control effects both the client and the server (if this header isn’t available).

See CacheControlError::InvalidUnit for available units.

Examples

To limit a response to be in the cache for 10 minutes, return kvarn-cache-control: 10m as a header in a reverse-proxied server or in a extension.

Errors

Can return CacheControlError::InvalidKeyword, CacheControlError::InvalidUnit, and CacheControlError::InvalidInteger.

Tries to get CacheControl from a HeaderMap.

See Self::from_kvarn_cache_control for more info about how the server cache directive is decided.

Errors

Same as Self::from_kvarn_cache_control and Self::from_cache_control with CacheControlError::InvalidBytes if HeaderValue::to_str returns an error.

Returns if you should cache.

Gets the freshness lifetime of this cache control directive. If the returned value is None, you should let it be in the cache for as long as possible, longer than any with a defined lifetime.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more