1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use super::{key::*, response::*};
//
// Cache
//
/// Cache.
///
/// Implementations should ensure that cloning is cheap and clones always refer to the same shared
/// state.
#[allow(async_fn_in_trait)]
pub trait Cache<CacheKeyT = CommonCacheKey>
where
Self: 'static + Clone + Send + Sync,
CacheKeyT: CacheKey,
{
/// Get an entry from the cache.
///
/// Note that this is an `async` function written in longer form in order to include the `Send`
/// constraint. Implementations can simply use `async fn put`.
fn get(&self, key: &CacheKeyT) -> impl Future<Output = Option<CachedResponseRef>> + Send;
/// Put an entry in the cache.
///
/// The cache should take into consideration the [CachedResponse::duration] if set.
///
/// Note that this is an `async` function written in longer form in order to include the `Send`
/// constraint. Implementations can simply use `async fn put`.
fn put(&self, key: CacheKeyT, cached_response: CachedResponseRef) -> impl Future<Output = ()> + Send;
/// Invalidate a cache entry.
///
/// Note that this is an `async` function written in longer form in order to include the `Send`
/// constraint. Implementations can simply use `async fn invalidate`.
fn invalidate(&self, key: &CacheKeyT) -> impl Future<Output = ()> + Send;
/// Invalidate all cache entries.
///
/// Note that this is an `async` function written in longer form in order to include the `Send`
/// constraint. Implementations can simply use `async fn invalidate_all`.
fn invalidate_all(&self) -> impl Future<Output = ()> + Send;
}