pub struct CacheLayer<C, K> { /* private fields */ }Expand description
The main struct of the library. The layer providing caching to the wrapped service.
It is generic over the cache used (C) and a Keyer (K) used to obtain the key for cached
responses.
Implementations§
Source§impl<C, K> CacheLayer<C, K>where
C: Cached<K::Key, CachedResponse> + CloneCached<K::Key, CachedResponse>,
K: Keyer,
K::Key: Debug + Hash + Eq + Clone + Send + 'static,
impl<C, K> CacheLayer<C, K>where
C: Cached<K::Key, CachedResponse> + CloneCached<K::Key, CachedResponse>,
K: Keyer,
K::Key: Debug + Hash + Eq + Clone + Send + 'static,
Sourcepub fn with_cache_and_keyer(cache: C, keyer: K) -> Self
pub fn with_cache_and_keyer(cache: C, keyer: K) -> 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<C> CacheLayer<C, BasicKeyer>
impl<C> CacheLayer<C, BasicKeyer>
Source§impl CacheLayer<TimedCache<BasicKey, CachedResponse>, BasicKey>
impl CacheLayer<TimedCache<BasicKey, CachedResponse>, BasicKey>
Sourcepub fn with_lifespan(
ttl: Duration,
) -> CacheLayer<TimedCache<BasicKey, CachedResponse>, BasicKeyer>
pub fn with_lifespan( ttl: Duration, ) -> CacheLayer<TimedCache<BasicKey, CachedResponse>, BasicKeyer>
Create a new cache layer with the desired TTL
Source§impl<K> CacheLayer<TimedCache<K::Key, CachedResponse>, K>
impl<K> CacheLayer<TimedCache<K::Key, CachedResponse>, K>
Sourcepub fn with_lifespan_and_keyer(
ttl: Duration,
keyer: K,
) -> CacheLayer<TimedCache<K::Key, CachedResponse>, K>
pub fn with_lifespan_and_keyer( ttl: Duration, keyer: K, ) -> CacheLayer<TimedCache<K::Key, CachedResponse>, K>
Create a new cache layer with the desired TTL