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 more