pub struct CacheLayer<C> { /* private fields */ }Expand description
The main struct of the library. The layer providing caching to the wrapped service.
Implementations§
source§impl<C> CacheLayer<C>
impl<C> CacheLayer<C>
sourcepub fn with(cache: C) -> Self
pub fn with(cache: C) -> Self
Create a new cache layer with a given cache and the default body size limit of 128 MB.
sourcepub fn use_stale_on_failure(self) -> Self
pub fn use_stale_on_failure(self) -> Self
Switch the layer’s settings to preserve the last successful response even when it’s evicted
from the cache but the service failed to provide a new successful response (ie. eg. when
the underlying service responds with 404 NOT FOUND, the cache will keep providing the last stale 200 OK
response produced).
sourcepub fn body_limit(self, new_limit: usize) -> Self
pub fn body_limit(self, new_limit: usize) -> Self
Change the maximum body size limit. If you want unlimited size, use usize::MAX.
sourcepub fn allow_invalidation(self) -> Self
pub fn allow_invalidation(self) -> Self
Allow manual cache invalidation by setting the X-Invalidate-Cache header in the request.
This will allow the cache to be invalidated for the given key.
sourcepub fn add_response_headers(self) -> Self
pub fn add_response_headers(self) -> Self
Allow the response headers to be included in the cached response.
source§impl CacheLayer<TimedCache<(Method, Uri), CachedResponse>>
impl CacheLayer<TimedCache<(Method, Uri), CachedResponse>>
sourcepub fn with_lifespan(
ttl_sec: u64,
) -> CacheLayer<TimedCache<(Method, Uri), CachedResponse>>
pub fn with_lifespan( ttl_sec: u64, ) -> CacheLayer<TimedCache<(Method, Uri), CachedResponse>>
Create a new cache layer with the desired TTL in seconds
Trait Implementations§
source§impl<C: Clone> Clone for CacheLayer<C>
impl<C: Clone> Clone for CacheLayer<C>
source§fn clone(&self) -> CacheLayer<C>
fn clone(&self) -> CacheLayer<C>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<C> Freeze for CacheLayer<C>
impl<C> RefUnwindSafe for CacheLayer<C>
impl<C> Send for CacheLayer<C>where
C: Send,
impl<C> Sync for CacheLayer<C>where
C: Send,
impl<C> Unpin for CacheLayer<C>
impl<C> UnwindSafe for CacheLayer<C>
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)