pub struct CacheControl {
pub directives: Vec<CacheDirective>,
}Expand description
Parsed or constructed Cache-Control header.
§Examples
§Parsing
use armature_core::response_cache::CacheControl;
let cc = CacheControl::parse("public, max-age=3600, must-revalidate");
assert!(cc.is_public());
assert_eq!(cc.get_max_age(), Some(3600));§Building
use armature_core::response_cache::CacheControl;
use std::time::Duration;
let cc = CacheControl::new()
.private()
.max_age(Duration::from_secs(300))
.no_transform();
assert!(cc.is_private());Fields§
§directives: Vec<CacheDirective>All directives in this Cache-Control header
Implementations§
Source§impl CacheControl
impl CacheControl
Sourcepub fn to_header_value(&self) -> String
pub fn to_header_value(&self) -> String
Convert to header value string.
Sourcepub fn s_maxage(self, duration: Duration) -> Self
pub fn s_maxage(self, duration: Duration) -> Self
Add the s-maxage directive for shared caches.
Sourcepub fn must_revalidate(self) -> Self
pub fn must_revalidate(self) -> Self
Add the must-revalidate directive.
Sourcepub fn proxy_revalidate(self) -> Self
pub fn proxy_revalidate(self) -> Self
Add the proxy-revalidate directive.
Sourcepub fn no_transform(self) -> Self
pub fn no_transform(self) -> Self
Add the no-transform directive.
Sourcepub fn directive(self, directive: CacheDirective) -> Self
pub fn directive(self, directive: CacheDirective) -> Self
Add a custom directive.
Sourcepub fn is_private(&self) -> bool
pub fn is_private(&self) -> bool
Check if private directive is present.
Sourcepub fn is_no_store(&self) -> bool
pub fn is_no_store(&self) -> bool
Check if no-store directive is present.
Sourcepub fn is_no_cache(&self) -> bool
pub fn is_no_cache(&self) -> bool
Check if no-cache directive is present.
Sourcepub fn is_must_revalidate(&self) -> bool
pub fn is_must_revalidate(&self) -> bool
Check if must-revalidate directive is present.
Sourcepub fn is_immutable(&self) -> bool
pub fn is_immutable(&self) -> bool
Check if immutable directive is present.
Sourcepub fn get_max_age(&self) -> Option<u64>
pub fn get_max_age(&self) -> Option<u64>
Get the max-age value in seconds.
Sourcepub fn get_s_maxage(&self) -> Option<u64>
pub fn get_s_maxage(&self) -> Option<u64>
Get the s-maxage value in seconds.
Sourcepub fn is_cacheable(&self) -> bool
pub fn is_cacheable(&self) -> bool
Check if the response is cacheable.
Sourcepub fn freshness_lifetime(&self) -> Option<u64>
pub fn freshness_lifetime(&self) -> Option<u64>
Get the freshness lifetime in seconds.
Returns s-maxage if present (for shared caches), otherwise max-age.
Sourcepub fn public_max_age(duration: Duration) -> Self
pub fn public_max_age(duration: Duration) -> Self
Create a public cache with the given max-age.
Sourcepub fn private_max_age(duration: Duration) -> Self
pub fn private_max_age(duration: Duration) -> Self
Create a private cache with the given max-age.
Sourcepub fn immutable_asset(duration: Duration) -> Self
pub fn immutable_asset(duration: Duration) -> Self
Create an immutable public cache (for versioned assets).
Sourcepub fn revalidate(duration: Duration) -> Self
pub fn revalidate(duration: Duration) -> Self
Create a must-revalidate cache.
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§fn default() -> CacheControl
fn default() -> CacheControl
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,
impl<R, D> DepsPresent<D> for R
Source§impl<T> Injectable for T
impl<T> Injectable for T
Source§fn type_id_of() -> TypeIdwhere
Self: Sized,
fn type_id_of() -> TypeIdwhere
Self: Sized,
Source§fn type_name_of() -> &'static strwhere
Self: Sized,
fn type_name_of() -> &'static strwhere
Self: Sized,
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>
impl<T> Provider for Twhere
T: Injectable,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more