pub trait Cache<CacheKeyT = CommonCacheKey>:
'static
+ Clone
+ Send
+ Syncwhere
CacheKeyT: CacheKey,{
// Required methods
fn get(
&self,
key: &CacheKeyT,
) -> impl Future<Output = Option<CachedResponseRef>> + Send;
fn put(
&self,
key: CacheKeyT,
cached_response: CachedResponseRef,
) -> impl Future<Output = ()> + Send;
fn invalidate(&self, key: &CacheKeyT) -> impl Future<Output = ()> + Send;
fn invalidate_all(&self) -> impl Future<Output = ()> + Send;
}
Expand description
Cache.
Cloning should be cheap! Wrapping an implementation Arc might be an easy solution.
Required Methods§
Sourcefn get(
&self,
key: &CacheKeyT,
) -> impl Future<Output = Option<CachedResponseRef>> + Send
fn get( &self, key: &CacheKeyT, ) -> impl Future<Output = Option<CachedResponseRef>> + Send
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
.
Sourcefn put(
&self,
key: CacheKeyT,
cached_response: CachedResponseRef,
) -> impl Future<Output = ()> + Send
fn put( &self, key: CacheKeyT, cached_response: CachedResponseRef, ) -> impl Future<Output = ()> + 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
.
Sourcefn invalidate(&self, key: &CacheKeyT) -> impl Future<Output = ()> + Send
fn invalidate(&self, key: &CacheKeyT) -> 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
.
Sourcefn invalidate_all(&self) -> impl Future<Output = ()> + Send
fn invalidate_all(&self) -> 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
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<CacheKeyT> Cache<CacheKeyT> for MokaCacheImplementation<CacheKeyT>where
CacheKeyT: CacheKey,
moka
only.