kutil_http/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: Sized {
13    /// Add support for [CachedResponse] weigher and [Expiry](moka::Expiry).
14    fn for_http_response(self) -> Self;
15}
16
17impl<CacheKeyT> ForHttpResponse
18    for moka::future::CacheBuilder<CacheKeyT, CachedResponseRef, moka::future::Cache<CacheKeyT, CachedResponseRef>>
19where
20    CacheKeyT: CacheKey,
21{
22    fn for_http_response(self) -> Self {
23        self.weigher(weigher).expire_after(CachedResponseExpiry)
24    }
25}