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