Struct CacheControl
pub struct CacheControl { /* private fields */ }http only.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§
§impl CacheControl
impl CacheControl
pub fn new() -> CacheControl
pub fn new() -> CacheControl
Construct a new empty CacheControl header.
pub fn immutable_one_year() -> CacheControl
pub fn immutable_one_year() -> CacheControl
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.
pub fn no_cache() -> CacheControl
pub fn no_cache() -> CacheControl
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.
pub fn has_no_cache(self) -> bool
pub fn has_no_cache(self) -> bool
Check if the no-cache directive is set.
pub fn has_no_store(self) -> bool
pub fn has_no_store(self) -> bool
Check if the no-store directive is set.
pub fn has_no_transform(self) -> bool
pub fn has_no_transform(self) -> bool
Check if the no-transform directive is set.
pub fn has_only_if_cached(self) -> bool
pub fn has_only_if_cached(self) -> bool
Check if the only-if-cached directive is set.
pub fn has_public(self) -> bool
pub fn has_public(self) -> bool
Check if the public directive is set.
pub fn has_private(self) -> bool
pub fn has_private(self) -> bool
Check if the private directive is set.
pub fn has_immutable(self) -> bool
pub fn has_immutable(self) -> bool
Check if the immutable directive is set.
pub fn has_must_revalidate(&self) -> bool
pub fn has_must_revalidate(&self) -> bool
Check if the must-revalidate directive is set.
pub fn has_must_understand(self) -> bool
pub fn has_must_understand(self) -> bool
Check if the must-understand directive is set.
pub fn with_no_cache(self) -> CacheControl
pub fn with_no_cache(self) -> CacheControl
Set the no-cache directive.
pub fn set_no_cache(&mut self) -> &mut CacheControl
pub fn set_no_cache(&mut self) -> &mut CacheControl
Set the no-cache directive.
pub fn with_no_store(self) -> CacheControl
pub fn with_no_store(self) -> CacheControl
Set the no-store directive.
pub fn set_no_store(&mut self) -> &mut CacheControl
pub fn set_no_store(&mut self) -> &mut CacheControl
Set the no-store directive.
pub fn with_no_transform(self) -> CacheControl
pub fn with_no_transform(self) -> CacheControl
Set the no-transform directive.
pub fn set_no_transform(&mut self) -> &mut CacheControl
pub fn set_no_transform(&mut self) -> &mut CacheControl
Set the no-transform directive.
pub fn with_only_if_cached(self) -> CacheControl
pub fn with_only_if_cached(self) -> CacheControl
Set the only-if-cached directive.
pub fn set_only_if_cached(&mut self) -> &mut CacheControl
pub fn set_only_if_cached(&mut self) -> &mut CacheControl
Set the only-if-cached directive.
pub fn with_private(self) -> CacheControl
pub fn with_private(self) -> CacheControl
Set the private directive.
pub fn set_private(&mut self) -> &mut CacheControl
pub fn set_private(&mut self) -> &mut CacheControl
Set the private directive.
pub fn with_public(self) -> CacheControl
pub fn with_public(self) -> CacheControl
Set the public directive.
pub fn set_public(&mut self) -> &mut CacheControl
pub fn set_public(&mut self) -> &mut CacheControl
Set the public directive.
pub fn with_immutable(self) -> CacheControl
pub fn with_immutable(self) -> CacheControl
Set the immutable directive.
pub fn set_immutable(&mut self) -> &mut CacheControl
pub fn set_immutable(&mut self) -> &mut CacheControl
Set the immutable directive.
pub fn with_must_revalidate(self) -> CacheControl
pub fn with_must_revalidate(self) -> CacheControl
Set the must-revalidate directive.
pub fn set_must_revalidate(&mut self) -> &mut CacheControl
pub fn set_must_revalidate(&mut self) -> &mut CacheControl
Set the must-revalidate directive.
pub fn with_must_understand(self) -> CacheControl
pub fn with_must_understand(self) -> CacheControl
Set the must-understand directive.
pub fn set_must_understand(&mut self) -> &mut CacheControl
pub fn set_must_understand(&mut self) -> &mut CacheControl
Set the must-understand directive.
pub fn with_max_age_duration_rounded(self, dur: Duration) -> CacheControl
pub fn with_max_age_duration_rounded(self, dur: Duration) -> CacheControl
Set the max-age directive.
pub fn set_max_age_duration_rounded(
&mut self,
dur: Duration,
) -> &mut CacheControl
pub fn set_max_age_duration_rounded( &mut self, dur: Duration, ) -> &mut CacheControl
Set the max-age directive.
pub fn with_max_age_seconds(self, seconds: u64) -> CacheControl
pub fn with_max_age_seconds(self, seconds: u64) -> CacheControl
Set the max-age directive.
pub fn set_max_age_seconds(&mut self, seconds: u64) -> &mut CacheControl
pub fn set_max_age_seconds(&mut self, seconds: u64) -> &mut CacheControl
Set the max-age directive.
pub fn try_with_max_age_duration(
self,
dur: Duration,
) -> Result<CacheControl, Box<dyn Error + Sync + Send>>
pub fn try_with_max_age_duration( self, dur: Duration, ) -> Result<CacheControl, Box<dyn Error + Sync + Send>>
Try to set the max-age directive.
pub fn try_set_max_age_duration(
&mut self,
dur: Duration,
) -> Result<&mut CacheControl, Box<dyn Error + Sync + Send>>
pub fn try_set_max_age_duration( &mut self, dur: Duration, ) -> Result<&mut CacheControl, Box<dyn Error + Sync + Send>>
Try to set the max-age directive.
pub fn with_max_stale_duration_rounded(self, dur: Duration) -> CacheControl
pub fn with_max_stale_duration_rounded(self, dur: Duration) -> CacheControl
Set the max-stale directive.
pub fn set_max_stale_duration_rounded(
&mut self,
dur: Duration,
) -> &mut CacheControl
pub fn set_max_stale_duration_rounded( &mut self, dur: Duration, ) -> &mut CacheControl
Set the max-stale directive.
pub fn with_max_stale_seconds(self, seconds: u64) -> CacheControl
pub fn with_max_stale_seconds(self, seconds: u64) -> CacheControl
Set the max-stale directive.
pub fn set_max_stale_seconds(&mut self, seconds: u64) -> &mut CacheControl
pub fn set_max_stale_seconds(&mut self, seconds: u64) -> &mut CacheControl
Set the max-stale directive.
pub fn try_with_max_stale_duration(
self,
dur: Duration,
) -> Result<CacheControl, Box<dyn Error + Sync + Send>>
pub fn try_with_max_stale_duration( self, dur: Duration, ) -> Result<CacheControl, Box<dyn Error + Sync + Send>>
Try to set the max-stale directive.
pub fn try_set_max_stale_duration(
&mut self,
dur: Duration,
) -> Result<&mut CacheControl, Box<dyn Error + Sync + Send>>
pub fn try_set_max_stale_duration( &mut self, dur: Duration, ) -> Result<&mut CacheControl, Box<dyn Error + Sync + Send>>
Try to set the max-stale directive.
pub fn with_min_fresh_duration_rounded(self, dur: Duration) -> CacheControl
pub fn with_min_fresh_duration_rounded(self, dur: Duration) -> CacheControl
Set the min-fresh directive.
pub fn set_min_fresh_duration_rounded(
&mut self,
dur: Duration,
) -> &mut CacheControl
pub fn set_min_fresh_duration_rounded( &mut self, dur: Duration, ) -> &mut CacheControl
Set the min-fresh directive.
pub fn with_min_fresh_seconds(self, seconds: u64) -> CacheControl
pub fn with_min_fresh_seconds(self, seconds: u64) -> CacheControl
Set the min-fresh directive.
pub fn set_min_fresh_seconds(&mut self, seconds: u64) -> &mut CacheControl
pub fn set_min_fresh_seconds(&mut self, seconds: u64) -> &mut CacheControl
Set the min-fresh directive.
pub fn try_with_min_fresh_duration(
self,
dur: Duration,
) -> Result<CacheControl, Box<dyn Error + Sync + Send>>
pub fn try_with_min_fresh_duration( self, dur: Duration, ) -> Result<CacheControl, Box<dyn Error + Sync + Send>>
Try to set the min-fresh directive.
pub fn try_set_min_fresh_duration(
&mut self,
dur: Duration,
) -> Result<&mut CacheControl, Box<dyn Error + Sync + Send>>
pub fn try_set_min_fresh_duration( &mut self, dur: Duration, ) -> Result<&mut CacheControl, Box<dyn Error + Sync + Send>>
Try to set the min-fresh directive.
pub fn with_s_max_age_duration_rounded(self, dur: Duration) -> CacheControl
pub fn with_s_max_age_duration_rounded(self, dur: Duration) -> CacheControl
Set the s-maxage directive.
pub fn set_s_max_age_duration_rounded(
&mut self,
dur: Duration,
) -> &mut CacheControl
pub fn set_s_max_age_duration_rounded( &mut self, dur: Duration, ) -> &mut CacheControl
Set the s-maxage directive.
pub fn with_s_max_age_seconds(self, seconds: u64) -> CacheControl
pub fn with_s_max_age_seconds(self, seconds: u64) -> CacheControl
Set the s-maxage directive.
pub fn set_s_max_age_seconds(&mut self, seconds: u64) -> &mut CacheControl
pub fn set_s_max_age_seconds(&mut self, seconds: u64) -> &mut CacheControl
Set the s-maxage directive.
pub fn try_with_s_max_age_duration(
self,
dur: Duration,
) -> Result<CacheControl, Box<dyn Error + Sync + Send>>
pub fn try_with_s_max_age_duration( self, dur: Duration, ) -> Result<CacheControl, Box<dyn Error + Sync + Send>>
Try to set the s-maxage directive.
pub fn try_set_s_max_age_duration(
&mut self,
dur: Duration,
) -> Result<&mut CacheControl, Box<dyn Error + Sync + Send>>
pub fn try_set_s_max_age_duration( &mut self, dur: Duration, ) -> Result<&mut CacheControl, Box<dyn Error + Sync + Send>>
Try to set the s-maxage directive.
Trait Implementations§
§impl Clone for CacheControl
impl Clone for CacheControl
§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 more§impl Debug for CacheControl
impl Debug for CacheControl
§impl Default for CacheControl
impl Default for CacheControl
§fn default() -> CacheControl
fn default() -> CacheControl
§impl HeaderDecode for CacheControl
impl HeaderDecode for CacheControl
§fn decode<'i, I>(values: &mut I) -> Result<CacheControl, Error>where
I: Iterator<Item = &'i HeaderValue>,
fn decode<'i, I>(values: &mut I) -> Result<CacheControl, Error>where
I: Iterator<Item = &'i HeaderValue>,
HeaderValues.§impl HeaderEncode for CacheControl
impl HeaderEncode for CacheControl
§fn encode<E>(&self, values: &mut E)where
E: Extend<HeaderValue>,
fn encode<E>(&self, values: &mut E)where
E: Extend<HeaderValue>,
HeaderValue, and add it to a container
which has HeaderValue type as each element. Read more§fn encode_to_value(&self) -> Option<HeaderValue>
fn encode_to_value(&self) -> Option<HeaderValue>
HeaderValue. Read more§impl PartialEq for CacheControl
impl PartialEq for CacheControl
impl StructuralPartialEq for CacheControl
§impl TypedHeader for CacheControl
impl TypedHeader for CacheControl
§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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>
§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writer§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writer§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writer§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writer§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer