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§
source§impl 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,
) -> Result<CacheControl, CacheControlError>
pub fn from_headers( headers: &HeaderMap, ) -> 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§
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 moreAuto Trait Implementations§
impl Freeze for CacheControl
impl RefUnwindSafe for CacheControl
impl Send for CacheControl
impl Sync for CacheControl
impl Unpin 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)