Struct http_cache_semantics::CachePolicy [−][src]
pub struct CachePolicy { /* fields omitted */ }
Identifies when responses can be reused from a cache, taking into account HTTP RFC 7234 rules for user agents and shared caches. It’s aware of many tricky details such as the Vary header, proxy revalidation, and authenticated responses.
Implementations
impl CachePolicy
[src]
impl CachePolicy
[src]pub fn new<Req: RequestLike, Res: ResponseLike>(req: &Req, res: &Res) -> Self
[src]
pub fn new<Req: RequestLike, Res: ResponseLike>(req: &Req, res: &Res) -> Self
[src]Cacheability of an HTTP response depends on how it was requested, so both request and response are required to create the policy.
pub fn new_options<Req: RequestLike, Res: ResponseLike>(
req: &Req,
res: &Res,
response_time: SystemTime,
opts: CacheOptions
) -> Self
[src]
pub fn new_options<Req: RequestLike, Res: ResponseLike>(
req: &Req,
res: &Res,
response_time: SystemTime,
opts: CacheOptions
) -> Self
[src]Caching with customized behavior. See CacheOptions
for details.
response_time
is a timestamp when the response has been received, usually SystemTime::now()
.
pub fn is_storable(&self) -> bool
[src]
pub fn is_storable(&self) -> bool
[src]Returns true
if the response can be stored in a cache. If it’s
false
then you MUST NOT store either the request or the response.
pub fn before_request<Req: RequestLike>(
&self,
req: &Req,
now: SystemTime
) -> BeforeRequest
[src]
pub fn before_request<Req: RequestLike>(
&self,
req: &Req,
now: SystemTime
) -> BeforeRequest
[src]Returns whether the cached response is still fresh in the context of the new request.
If it returns true
, then the given request matches the original
response this cache policy has been created with, and the response can
be reused without contacting the server.
If it returns false
, then the response may not be matching at all
(e.g. it’s for a different URL or method), or may require to be
refreshed first. Either way, the new request’s headers will have been
updated for sending it to the origin server.
pub fn age(&self, now: SystemTime) -> Duration
[src]
pub fn age(&self, now: SystemTime) -> Duration
[src]Tells how long the response has been sitting in cache(s).
Value of the Age
header, updated for the current time.
pub fn time_to_live(&self, now: SystemTime) -> Duration
[src]
pub fn time_to_live(&self, now: SystemTime) -> Duration
[src]Returns approximate time in milliseconds until the response becomes stale (i.e. not fresh).
After that time (when time_to_live() <= 0
) the response might not be
usable without revalidation. However, there are exceptions, e.g. a
client can explicitly allow stale responses, so always check with
before_request()
.
pub fn is_stale(&self, now: SystemTime) -> bool
[src]
pub fn is_stale(&self, now: SystemTime) -> bool
[src]Stale responses shouldn’t be used without contacting the server (revalidation)
pub fn after_response<Req: RequestLike, Res: ResponseLike>(
&self,
request: &Req,
response: &Res,
response_time: SystemTime
) -> AfterResponse
[src]
pub fn after_response<Req: RequestLike, Res: ResponseLike>(
&self,
request: &Req,
response: &Res,
response_time: SystemTime
) -> AfterResponse
[src]Creates CachePolicy
with information combined from the previews response,
and the new revalidation response.
Returns {policy, modified}
where modified is a boolean indicating
whether the response body has been modified, and old cached body can’t be used.
Trait Implementations
impl Debug for CachePolicy
[src]
impl Debug for CachePolicy
[src]impl<'de> Deserialize<'de> for CachePolicy
[src]
impl<'de> Deserialize<'de> for CachePolicy
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
impl Serialize for CachePolicy
[src]
impl Serialize for CachePolicy
[src]Auto Trait Implementations
impl RefUnwindSafe for CachePolicy
impl Send for CachePolicy
impl Sync for CachePolicy
impl Unpin for CachePolicy
impl UnwindSafe for CachePolicy
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,