kutil_http/cache/
cache.rs

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