pub struct CacheControl { /* private fields */ }Expand description
Cache-Control header, defined in RFC7234
with extensions in RFC8246
The Cache-Control header field is used to specify directives for
caches along the request/response chain. Such cache directives are
unidirectional in that the presence of a directive in a request does
not imply that the same directive is to be given in the response.
§ABNF
Cache-Control = 1#cache-directive
cache-directive = token [ "=" ( token / quoted-string ) ]§Example values
no-cacheprivate, community="UCI"max-age=30
§Example
use rama_http_headers::CacheControl;
let cc = CacheControl::new();Implementations§
Source§impl CacheControl
impl CacheControl
Sourcepub fn immutable_one_year() -> Self
pub fn immutable_one_year() -> Self
public, immutable, max-age=31536000 — for content-hashed /
versioned URLs (e.g. /theme.css?v=<git-sha>).
The URL changes whenever the content changes, so the cached response
is safe to keep for a year; immutable additionally stops the browser
from revalidating on reload. Reach for this only on content-hashed
URLs — on a stable URL whose body can change in place, use
Self::no_cache or Self::short_shared_revalidate instead.
Sourcepub fn no_cache() -> Self
pub fn no_cache() -> Self
no-cache — the response is cacheable but must be revalidated with
the origin before reuse.
The right default for service-worker scripts, HTML, or anything whose URL is stable but whose body may change in place.
public, max-age=<secs>, must-revalidate — a short shared cache for
non-fingerprinted but rarely-changing files (robots.txt,
sitemap.xml, security.txt).
Lets a CDN absorb crawler bursts without making content updates invisible for long.
Sourcepub fn has_no_cache(self) -> bool
pub fn has_no_cache(self) -> bool
Check if the no-cache directive is set.
Sourcepub fn has_no_store(self) -> bool
pub fn has_no_store(self) -> bool
Check if the no-store directive is set.
Sourcepub fn has_no_transform(self) -> bool
pub fn has_no_transform(self) -> bool
Check if the no-transform directive is set.
Sourcepub fn has_only_if_cached(self) -> bool
pub fn has_only_if_cached(self) -> bool
Check if the only-if-cached directive is set.
Sourcepub fn has_public(self) -> bool
pub fn has_public(self) -> bool
Check if the public directive is set.
Sourcepub fn has_private(self) -> bool
pub fn has_private(self) -> bool
Check if the private directive is set.
Sourcepub fn has_immutable(self) -> bool
pub fn has_immutable(self) -> bool
Check if the immutable directive is set.
Sourcepub fn has_must_revalidate(&self) -> bool
pub fn has_must_revalidate(&self) -> bool
Check if the must-revalidate directive is set.
Sourcepub fn has_must_understand(self) -> bool
pub fn has_must_understand(self) -> bool
Check if the must-understand directive is set.
Sourcepub fn with_no_cache(self) -> Self
pub fn with_no_cache(self) -> Self
Set the no-cache directive.
Sourcepub fn set_no_cache(&mut self) -> &mut Self
pub fn set_no_cache(&mut self) -> &mut Self
Set the no-cache directive.
Sourcepub fn with_no_store(self) -> Self
pub fn with_no_store(self) -> Self
Set the no-store directive.
Sourcepub fn set_no_store(&mut self) -> &mut Self
pub fn set_no_store(&mut self) -> &mut Self
Set the no-store directive.
Sourcepub fn with_no_transform(self) -> Self
pub fn with_no_transform(self) -> Self
Set the no-transform directive.
Sourcepub fn set_no_transform(&mut self) -> &mut Self
pub fn set_no_transform(&mut self) -> &mut Self
Set the no-transform directive.
Sourcepub fn with_only_if_cached(self) -> Self
pub fn with_only_if_cached(self) -> Self
Set the only-if-cached directive.
Sourcepub fn set_only_if_cached(&mut self) -> &mut Self
pub fn set_only_if_cached(&mut self) -> &mut Self
Set the only-if-cached directive.
Sourcepub fn with_private(self) -> Self
pub fn with_private(self) -> Self
Set the private directive.
Sourcepub fn set_private(&mut self) -> &mut Self
pub fn set_private(&mut self) -> &mut Self
Set the private directive.
Sourcepub fn with_public(self) -> Self
pub fn with_public(self) -> Self
Set the public directive.
Sourcepub fn set_public(&mut self) -> &mut Self
pub fn set_public(&mut self) -> &mut Self
Set the public directive.
Sourcepub fn with_immutable(self) -> Self
pub fn with_immutable(self) -> Self
Set the immutable directive.
Sourcepub fn set_immutable(&mut self) -> &mut Self
pub fn set_immutable(&mut self) -> &mut Self
Set the immutable directive.
Sourcepub fn with_must_revalidate(self) -> Self
pub fn with_must_revalidate(self) -> Self
Set the must-revalidate directive.
Sourcepub fn set_must_revalidate(&mut self) -> &mut Self
pub fn set_must_revalidate(&mut self) -> &mut Self
Set the must-revalidate directive.
Sourcepub fn with_must_understand(self) -> Self
pub fn with_must_understand(self) -> Self
Set the must-understand directive.
Sourcepub fn set_must_understand(&mut self) -> &mut Self
pub fn set_must_understand(&mut self) -> &mut Self
Set the must-understand directive.
Sourcepub fn with_max_age_duration_rounded(self, dur: Duration) -> Self
pub fn with_max_age_duration_rounded(self, dur: Duration) -> Self
Set the max-age directive.
Sourcepub fn set_max_age_duration_rounded(&mut self, dur: Duration) -> &mut Self
pub fn set_max_age_duration_rounded(&mut self, dur: Duration) -> &mut Self
Set the max-age directive.
Sourcepub fn with_max_age_seconds(self, seconds: u64) -> Self
pub fn with_max_age_seconds(self, seconds: u64) -> Self
Set the max-age directive.
Sourcepub fn set_max_age_seconds(&mut self, seconds: u64) -> &mut Self
pub fn set_max_age_seconds(&mut self, seconds: u64) -> &mut Self
Set the max-age directive.
Sourcepub fn try_with_max_age_duration(self, dur: Duration) -> Result<Self, BoxError>
pub fn try_with_max_age_duration(self, dur: Duration) -> Result<Self, BoxError>
Try to set the max-age directive.
Sourcepub fn try_set_max_age_duration(
&mut self,
dur: Duration,
) -> Result<&mut Self, BoxError>
pub fn try_set_max_age_duration( &mut self, dur: Duration, ) -> Result<&mut Self, BoxError>
Try to set the max-age directive.
Sourcepub fn with_max_stale_duration_rounded(self, dur: Duration) -> Self
pub fn with_max_stale_duration_rounded(self, dur: Duration) -> Self
Set the max-stale directive.
Sourcepub fn set_max_stale_duration_rounded(&mut self, dur: Duration) -> &mut Self
pub fn set_max_stale_duration_rounded(&mut self, dur: Duration) -> &mut Self
Set the max-stale directive.
Sourcepub fn with_max_stale_seconds(self, seconds: u64) -> Self
pub fn with_max_stale_seconds(self, seconds: u64) -> Self
Set the max-stale directive.
Sourcepub fn set_max_stale_seconds(&mut self, seconds: u64) -> &mut Self
pub fn set_max_stale_seconds(&mut self, seconds: u64) -> &mut Self
Set the max-stale directive.
Sourcepub fn try_with_max_stale_duration(
self,
dur: Duration,
) -> Result<Self, BoxError>
pub fn try_with_max_stale_duration( self, dur: Duration, ) -> Result<Self, BoxError>
Try to set the max-stale directive.
Sourcepub fn try_set_max_stale_duration(
&mut self,
dur: Duration,
) -> Result<&mut Self, BoxError>
pub fn try_set_max_stale_duration( &mut self, dur: Duration, ) -> Result<&mut Self, BoxError>
Try to set the max-stale directive.
Sourcepub fn with_min_fresh_duration_rounded(self, dur: Duration) -> Self
pub fn with_min_fresh_duration_rounded(self, dur: Duration) -> Self
Set the min-fresh directive.
Sourcepub fn set_min_fresh_duration_rounded(&mut self, dur: Duration) -> &mut Self
pub fn set_min_fresh_duration_rounded(&mut self, dur: Duration) -> &mut Self
Set the min-fresh directive.
Sourcepub fn with_min_fresh_seconds(self, seconds: u64) -> Self
pub fn with_min_fresh_seconds(self, seconds: u64) -> Self
Set the min-fresh directive.
Sourcepub fn set_min_fresh_seconds(&mut self, seconds: u64) -> &mut Self
pub fn set_min_fresh_seconds(&mut self, seconds: u64) -> &mut Self
Set the min-fresh directive.
Sourcepub fn try_with_min_fresh_duration(
self,
dur: Duration,
) -> Result<Self, BoxError>
pub fn try_with_min_fresh_duration( self, dur: Duration, ) -> Result<Self, BoxError>
Try to set the min-fresh directive.
Sourcepub fn try_set_min_fresh_duration(
&mut self,
dur: Duration,
) -> Result<&mut Self, BoxError>
pub fn try_set_min_fresh_duration( &mut self, dur: Duration, ) -> Result<&mut Self, BoxError>
Try to set the min-fresh directive.
Sourcepub fn with_s_max_age_duration_rounded(self, dur: Duration) -> Self
pub fn with_s_max_age_duration_rounded(self, dur: Duration) -> Self
Set the s-maxage directive.
Sourcepub fn set_s_max_age_duration_rounded(&mut self, dur: Duration) -> &mut Self
pub fn set_s_max_age_duration_rounded(&mut self, dur: Duration) -> &mut Self
Set the s-maxage directive.
Sourcepub fn with_s_max_age_seconds(self, seconds: u64) -> Self
pub fn with_s_max_age_seconds(self, seconds: u64) -> Self
Set the s-maxage directive.
Sourcepub fn set_s_max_age_seconds(&mut self, seconds: u64) -> &mut Self
pub fn set_s_max_age_seconds(&mut self, seconds: u64) -> &mut Self
Set the s-maxage directive.
Sourcepub fn try_with_s_max_age_duration(
self,
dur: Duration,
) -> Result<Self, BoxError>
pub fn try_with_s_max_age_duration( self, dur: Duration, ) -> Result<Self, BoxError>
Try to set the s-maxage directive.
Sourcepub fn try_set_s_max_age_duration(
&mut self,
dur: Duration,
) -> Result<&mut Self, BoxError>
pub fn try_set_s_max_age_duration( &mut self, dur: Duration, ) -> Result<&mut Self, BoxError>
Try to set the s-maxage directive.
Trait Implementations§
Source§impl Clone for CacheControl
impl Clone for CacheControl
Source§fn clone(&self) -> CacheControl
fn clone(&self) -> CacheControl
1.0.0 (const: unstable) · 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§impl HeaderDecode for CacheControl
impl HeaderDecode for CacheControl
Source§fn decode<'i, I: Iterator<Item = &'i HeaderValue>>(
values: &mut I,
) -> Result<Self, Error>
fn decode<'i, I: Iterator<Item = &'i HeaderValue>>( values: &mut I, ) -> Result<Self, Error>
HeaderValues.Source§impl HeaderEncode for CacheControl
impl HeaderEncode for CacheControl
Source§fn encode<E: Extend<HeaderValue>>(&self, values: &mut E)
fn encode<E: Extend<HeaderValue>>(&self, values: &mut E)
HeaderValue, and add it to a container
which has HeaderValue type as each element. Read moreSource§fn encode_to_value(&self) -> Option<HeaderValue>
fn encode_to_value(&self) -> Option<HeaderValue>
HeaderValue. Read moreSource§impl PartialEq for CacheControl
impl PartialEq for CacheControl
Source§fn eq(&self, other: &CacheControl) -> bool
fn eq(&self, other: &CacheControl) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for CacheControl
Source§impl TypedHeader for CacheControl
impl TypedHeader for CacheControl
Source§fn name() -> &'static HeaderName
fn name() -> &'static HeaderName
Auto Trait Implementations§
impl Freeze for CacheControl
impl RefUnwindSafe for CacheControl
impl Send for CacheControl
impl Sync for CacheControl
impl Unpin for CacheControl
impl UnsafeUnpin for CacheControl
impl UnwindSafe for CacheControl
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more