pingora_cache::cache_control

Trait InterpretCacheControl

Source
pub trait InterpretCacheControl {
    // Required methods
    fn is_cacheable(&self) -> Cacheable;
    fn allow_caching_authorized_req(&self) -> bool;
    fn fresh_sec(&self) -> Option<u32>;
    fn serve_stale_while_revalidate_sec(&self) -> Option<u32>;
    fn serve_stale_if_error_sec(&self) -> Option<u32>;
    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§

Source

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.

Source

fn allow_caching_authorized_req(&self) -> bool

Does this cache-control allow caching a response to a request with the Authorization header?

Source

fn fresh_sec(&self) -> Option<u32>

Returns freshness ttl specified in cache-control

  • Some(_) indicates cache-control specifies a valid ttl. Some(0) = always stale.
  • None means cache-control did not specify a valid ttl.
Source

fn serve_stale_while_revalidate_sec(&self) -> Option<u32>

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.

Source

fn serve_stale_if_error_sec(&self) -> Option<u32>

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.

Source

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.

Implementors§