pub struct CacheControl { /* private fields */ }
Expand description
Directives to limit cache lifetime, read from cache-control
and kvarn-cache-control
headers.
See Self::from_cache_control
and Self::from_kvarn_cache_control
for respective parsing.
Implementations
sourceimpl CacheControl
impl CacheControl
sourcepub fn from_cache_control(
header: &str
) -> Result<CacheControl, CacheControlError>
pub fn from_cache_control(
header: &str
) -> Result<CacheControl, CacheControlError>
Respects max-age=
and no-store
parts of cache-control
header.
Uses the standard syntax.
Errors
Can return CacheControlError::MultipleMaxAge
and CacheControlError::InvalidInteger
.
sourcepub fn from_kvarn_cache_control(
header: &str
) -> Result<CacheControl, CacheControlError>
pub fn from_kvarn_cache_control(
header: &str
) -> Result<CacheControl, CacheControlError>
Converts a kvarn-cache-control
header to a CacheControl
directive.
The kvarn-cache-control
header is used for reverse-proxy servers and other downstream sources to
signal how Kvarn should cache their content. This header is prioritized over cache-control
, but serves a
similar function. This only applies to the server cache, whereas cache-control
effects both the client
and the server (if this header isn’t available).
See CacheControlError::InvalidUnit
for available units.
Examples
To limit a response to be in the cache for 10 minutes,
return kvarn-cache-control: 10m
as a header in a
reverse-proxied server or in a extension.
Errors
Can return CacheControlError::InvalidKeyword
, CacheControlError::InvalidUnit
,
and CacheControlError::InvalidInteger
.
sourcepub fn from_headers(
headers: &HeaderMap<HeaderValue>
) -> Result<CacheControl, CacheControlError>
pub fn from_headers(
headers: &HeaderMap<HeaderValue>
) -> Result<CacheControl, CacheControlError>
Tries to get CacheControl
from a HeaderMap
.
See Self::from_kvarn_cache_control
for more info about how the
server cache directive is decided.
Errors
Same as Self::from_kvarn_cache_control
and Self::from_cache_control
with
CacheControlError::InvalidBytes
if HeaderValue::to_str
returns an error.
sourcepub fn as_freshness(&self) -> Option<u32>
pub fn as_freshness(&self) -> Option<u32>
Gets the freshness lifetime of this cache control directive.
If the returned value is None
, you should let it be in the cache for as long as possible,
longer than any with a defined lifetime.
Trait Implementations
sourceimpl Clone for CacheControl
impl Clone for CacheControl
sourcefn clone(&self) -> CacheControl
fn clone(&self) -> CacheControl
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl RefUnwindSafe for CacheControl
impl Send for CacheControl
impl Sync for CacheControl
impl Unpin for CacheControl
impl UnwindSafe for CacheControl
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T> where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more