Trait Cache

Source
pub trait Cache<CacheKeyT = CommonCacheKey>:
    'static
    + Clone
    + Send
    + Sync
where 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§

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl<CacheKeyT> Cache<CacheKeyT> for MokaCacheImplementation<CacheKeyT>
where CacheKeyT: CacheKey,

Available on crate feature moka only.
Source§

impl<CacheKeyT, FirstCacheT, NextCacheT> Cache<CacheKeyT> for TieredCache<FirstCacheT, NextCacheT>
where CacheKeyT: CacheKey, FirstCacheT: Cache<CacheKeyT>, NextCacheT: Cache<CacheKeyT>,