pub struct CacheLayer<Req, K> { /* private fields */ }Expand description
A Tower Layer that applies response caching to a service.
This layer wraps a service with a Cache middleware that stores
successful responses and returns cached values for subsequent requests
with the same key.
§Examples
use tower_resilience_cache::CacheConfig;
use tower::ServiceBuilder;
use std::time::Duration;
let cache_layer = CacheConfig::builder()
.max_size(100)
.ttl(Duration::from_secs(60))
.key_extractor(|req: &String| req.clone())
.build();
let service = ServiceBuilder::new()
.layer(cache_layer)
.service(my_service());Implementations§
Source§impl<Req, K> CacheLayer<Req, K>
impl<Req, K> CacheLayer<Req, K>
Sourcepub fn new(config: CacheConfig<Req, K>) -> Self
pub fn new(config: CacheConfig<Req, K>) -> Self
Creates a new CacheLayer with the given configuration.
Trait Implementations§
Source§impl<Req: Clone, K: Clone> Clone for CacheLayer<Req, K>
impl<Req: Clone, K: Clone> Clone for CacheLayer<Req, K>
Source§fn clone(&self) -> CacheLayer<Req, K>
fn clone(&self) -> CacheLayer<Req, K>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<S, Req, K> Layer<S> for CacheLayer<Req, K>
impl<S, Req, K> Layer<S> for CacheLayer<Req, K>
Auto Trait Implementations§
impl<Req, K> Freeze for CacheLayer<Req, K>
impl<Req, K> !RefUnwindSafe for CacheLayer<Req, K>
impl<Req, K> Send for CacheLayer<Req, K>
impl<Req, K> Sync for CacheLayer<Req, K>
impl<Req, K> Unpin for CacheLayer<Req, K>
impl<Req, K> !UnwindSafe for CacheLayer<Req, K>
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