Skip to main content

tower_http_cache_plus/cache/implementation/moka/
builder.rs

1use super::{
2    super::super::{key::*, response::*},
3    expiry::*,
4    weigher::*,
5};
6
7//
8// ForHttpResponse
9//
10
11/// Add support for [CachedResponse] weigher and [Expiry](moka::Expiry).
12pub trait ForHttpResponse
13where
14    Self: Sized,
15{
16    /// Add support for [CachedResponse] weigher and [Expiry](moka::Expiry).
17    fn for_http_response(self) -> Self;
18}
19
20impl<CacheKeyT> ForHttpResponse
21    for moka::future::CacheBuilder<CacheKeyT, CachedResponseRef, moka::future::Cache<CacheKeyT, CachedResponseRef>>
22where
23    CacheKeyT: CacheKey,
24{
25    fn for_http_response(self) -> Self {
26        self.weigher(weigher).expire_after(CachedResponseExpiry)
27    }
28}