[−][src]Struct http_cache_semantics::CachePolicy
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.
Methods
impl CachePolicy
[src]
pub fn new<Req: RequestLike, Res: ResponseLike>(
req: &Req,
res: &Res,
opts: CachePolicyOptions
) -> Self
[src]
req: &Req,
res: &Res,
opts: CachePolicyOptions
) -> Self
Cacheability of an HTTP response depends on how it was requested, so both request and response are required to create the policy.
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 satisfies_without_revalidation<Req: RequestLike>(
&self,
req: &Req,
now: SystemTime
) -> bool
[src]
&self,
req: &Req,
now: SystemTime
) -> bool
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 cached_response(&self, now: SystemTime) -> Parts
[src]
Updates and filters the response headers for a cached response before returning it to a client. This function is necessary, because proxies MUST always remove hop-by-hop headers (such as TE and Connection) and update response's Age to avoid doubling cache time.
It returns response "parts" without a body. You can upgrade it to a full
response with Response::from_parts(parts, BYOB)
pub fn age(&self, now: SystemTime) -> Duration
[src]
Value of the Age header, in seconds, updated for the current time.
pub fn max_age(&self) -> Duration
[src]
Value of applicable max-age (or heuristic equivalent) in seconds. This counts since response's Date
.
For an up-to-date value, see time_to_live()
.
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
satisfies_without_revalidation()
.
pub fn is_stale(&self, now: SystemTime) -> bool
[src]
Stale responses shouldn't be used without contacting the server (revalidation)
pub fn revalidation_request<Req: RequestLike>(
&self,
incoming_req: &Req
) -> Parts
[src]
&self,
incoming_req: &Req
) -> Parts
Headers for sending to the origin server to revalidate stale response. Allows server to return 304 to allow reuse of the previous response.
Hop by hop headers are always stripped. Revalidation headers may be added or removed, depending on request.
It returns request "parts" without a body. You can upgrade it to a full
response with Request::from_parts(parts, BYOB)
(the body is usually ()
).
pub fn revalidated_policy<Req: RequestLike, Res: ResponseLike>(
&self,
request: &Req,
response: &Res,
response_time: SystemTime
) -> RevalidatedPolicy
[src]
&self,
request: &Req,
response: &Res,
response_time: SystemTime
) -> RevalidatedPolicy
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<'de> Deserialize<'de> for CachePolicy
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,