#[non_exhaustive]pub struct CacheControl {Show 15 fields
pub public: bool,
pub private: bool,
pub no_cache: bool,
pub no_store: bool,
pub no_transform: bool,
pub must_revalidate: bool,
pub proxy_revalidate: bool,
pub immutable: bool,
pub max_age: Option<u64>,
pub s_maxage: Option<u64>,
pub stale_while_revalidate: Option<u64>,
pub stale_if_error: Option<u64>,
pub only_if_cached: bool,
pub max_stale: Option<u64>,
pub min_fresh: Option<u64>,
}Expand description
Structured Cache-Control header (RFC 7234 §5.2).
All boolean directives default to false; numeric directives default to
None (absent). Use the builder methods to set them.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.public: boolpublic — response may be stored by any cache.
private: boolprivate — response is intended for a single user; must not be stored
by a shared cache.
no_cache: boolno-cache — cache must revalidate with the origin before serving.
no_store: boolno-store — must not store any part of the request or response.
no_transform: boolno-transform — no transformations or conversions should be made.
must_revalidate: boolmust-revalidate — stale responses must not be used without revalidation.
proxy_revalidate: boolproxy-revalidate — like must-revalidate but only for shared caches.
immutable: boolimmutable — response body will not change over its lifetime.
max_age: Option<u64>max-age=<seconds> — maximum time the response is considered fresh.
s_maxage: Option<u64>s-maxage=<seconds> — overrides max-age for shared caches.
stale_while_revalidate: Option<u64>stale-while-revalidate=<seconds> — serve stale while revalidating.
stale_if_error: Option<u64>stale-if-error=<seconds> — use stale response on error.
only_if_cached: boolonly-if-cached — do not use the network; only return a cached response.
max_stale: Option<u64>max-stale[=<seconds>] — accept a response up to this many seconds stale.
Some(0) means any staleness is acceptable; None means the directive
is absent.
min_fresh: Option<u64>min-fresh=<seconds> — require at least this much remaining freshness.
Implementations§
Source§impl CacheControl
impl CacheControl
Sourcepub fn no_transform(self) -> Self
pub fn no_transform(self) -> Self
Set the no-transform directive.
Sourcepub fn must_revalidate(self) -> Self
pub fn must_revalidate(self) -> Self
Set the must-revalidate directive.
Sourcepub fn proxy_revalidate(self) -> Self
pub fn proxy_revalidate(self) -> Self
Set the proxy-revalidate directive.
Sourcepub fn stale_while_revalidate(self, seconds: u64) -> Self
pub fn stale_while_revalidate(self, seconds: u64) -> Self
Set stale-while-revalidate=<seconds>.
Sourcepub fn stale_if_error(self, seconds: u64) -> Self
pub fn stale_if_error(self, seconds: u64) -> Self
Set stale-if-error=<seconds>.
Sourcepub fn only_if_cached(self) -> Self
pub fn only_if_cached(self) -> Self
Set the only-if-cached directive.
Sourcepub fn max_stale(self, seconds: u64) -> Self
pub fn max_stale(self, seconds: u64) -> Self
Set max-stale[=<seconds>]. Pass 0 to accept any staleness.
Sourcepub fn no_caching() -> Self
pub fn no_caching() -> Self
Convenience: no-store (disable all caching).
use api_bones::cache::CacheControl;
let cc = CacheControl::no_caching();
assert!(cc.no_store);
assert_eq!(cc.to_string(), "no-store");Sourcepub fn private_no_cache() -> Self
pub fn private_no_cache() -> Self
Convenience: private, no-cache, no-store.
use api_bones::cache::CacheControl;
let cc = CacheControl::private_no_cache();
assert!(cc.private && cc.no_cache && cc.no_store);Trait Implementations§
Source§impl Clone for CacheControl
impl Clone for CacheControl
Source§fn clone(&self) -> CacheControl
fn clone(&self) -> CacheControl
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CacheControl
impl Debug for CacheControl
Source§impl Default for CacheControl
impl Default for CacheControl
Source§fn default() -> CacheControl
fn default() -> CacheControl
Source§impl<'de> Deserialize<'de> for CacheControl
impl<'de> Deserialize<'de> for CacheControl
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for CacheControl
impl Display for CacheControl
Source§impl FromStr for CacheControl
impl FromStr for CacheControl
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parse a Cache-Control header value.
Unknown directives are silently ignored, matching real-world HTTP caching behaviour.
use api_bones::cache::CacheControl;
let cc: CacheControl = "public, max-age=3600, must-revalidate".parse().unwrap();
assert!(cc.public);
assert_eq!(cc.max_age, Some(3600));
assert!(cc.must_revalidate);