Skip to main content

tower_http_cache_plus/cache/implementation/moka/
expiry.rs

1use super::super::super::{key::*, response::*};
2
3use {duration_str::*, moka::*, std::time::*};
4
5//
6// CachedResponseExpiry
7//
8
9/// Moka [Expiry] for [CachedResponse].
10pub struct CachedResponseExpiry;
11
12impl<CacheKeyT> Expiry<CacheKeyT, CachedResponseRef> for CachedResponseExpiry
13where
14    CacheKeyT: CacheKey,
15{
16    fn expire_after_create(
17        &self,
18        _cache_key: &CacheKeyT,
19        cached_response: &CachedResponseRef,
20        _created_at: Instant,
21    ) -> Option<Duration> {
22        if let Some(duration) = cached_response.duration {
23            tracing::debug!("storing with duration: {}", duration.human_format());
24        }
25
26        cached_response.duration
27    }
28}