pub trait InterpretCacheControl {
// Required methods
fn is_cacheable(&self) -> Cacheable;
fn allow_caching_authorized_req(&self) -> bool;
fn fresh_duration(&self) -> Option<Duration>;
fn serve_stale_while_revalidate_duration(&self) -> Option<Duration>;
fn serve_stale_if_error_duration(&self) -> Option<Duration>;
fn strip_private_headers(&self, resp_header: &mut ResponseHeader);
}Expand description
InterpretCacheControl provides a meaningful interface to the parsed CacheControl.
These functions actually interpret the parsed cache-control directives to return
the freshness or other cache meta values that cache-control is signaling.
By default CacheControl implements an RFC-7234 compliant reading that assumes it is being
used with a shared (proxy) cache.
Required Methods§
Sourcefn is_cacheable(&self) -> Cacheable
fn is_cacheable(&self) -> Cacheable
Does cache-control specify this response is cacheable?
Note that an RFC-7234 compliant cacheability check must also
check if the request contained the Authorization header and
allow_caching_authorized_req.
Does this cache-control allow caching a response to a request with the Authorization header?
Sourcefn fresh_duration(&self) -> Option<Duration>
fn fresh_duration(&self) -> Option<Duration>
Returns freshness ttl specified in cache-control
Some(_)indicates cache-control specifies a valid ttl. Some(Duration::ZERO) = always stale.Nonemeans cache-control did not specify a valid ttl.
Sourcefn serve_stale_while_revalidate_duration(&self) -> Option<Duration>
fn serve_stale_while_revalidate_duration(&self) -> Option<Duration>
Returns stale-while-revalidate ttl,
The result should consider all the relevant cache directives, not just SWR header itself.
Some(0) means serving such stale is disallowed by directive like must-revalidate
or stale-while-revalidater=0.
None indicates no SWR ttl was specified.
Sourcefn serve_stale_if_error_duration(&self) -> Option<Duration>
fn serve_stale_if_error_duration(&self) -> Option<Duration>
Returns stale-if-error ttl,
The result should consider all the relevant cache directives, not just SIE header itself.
Some(0) means serving such stale is disallowed by directive like must-revalidate
or stale-if-error=0.
None indicates no SIE ttl was specified.
Sourcefn strip_private_headers(&self, resp_header: &mut ResponseHeader)
fn strip_private_headers(&self, resp_header: &mut ResponseHeader)
Strip header names listed in private or no-cache directives from a response,
usually prior to storing that response in cache.