pub struct Cache<S> { /* private fields */ }
Expand description
Implement a HTTP cache.
Implementations§
Source§impl<S> Cache<S>where
S: CacheStorage,
impl<S> Cache<S>where
S: CacheStorage,
Sourcepub fn new(storage: S) -> Self
pub fn new(storage: S) -> Self
Construct a new cache with the given storage.
Defaults to a private cache.
Sourcepub fn new_with_options(storage: S, options: CacheOptions) -> Self
pub fn new_with_options(storage: S, options: CacheOptions) -> Self
Construct a new cache with the given storage and options.
Sourcepub async fn send<B: HttpBody>(
&self,
request: impl Request<B>,
) -> Result<Response<Body<B>>>
pub async fn send<B: HttpBody>( &self, request: impl Request<B>, ) -> Result<Response<Body<B>>>
Sends a HTTP request through the cache.
If a previous response is cached and not stale, the request is not sent upstream and the cached response is returned.
If a previous response is cached and is stale, the response is revalidated, the cache is updated, and the cached response returned.
If a previous response is not in the cache, the request is sent upstream and the response is cached, if it is cacheable.
Auto Trait Implementations§
impl<S> Freeze for Cache<S>where
S: Freeze,
impl<S> RefUnwindSafe for Cache<S>where
S: RefUnwindSafe,
impl<S> Send for Cache<S>where
S: Send,
impl<S> Sync for Cache<S>where
S: Sync,
impl<S> Unpin for Cache<S>where
S: Unpin,
impl<S> UnwindSafe for Cache<S>where
S: UnwindSafe,
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
Mutably borrows from an owned value. Read more