CacheBackend

Trait CacheBackend 

Source
pub trait CacheBackend<V>: Send + Sync
where V: Send + Sync,
{ // Required methods fn get<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Option<V>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn insert<'life0, 'async_trait>( &'life0 self, key: String, value: V, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn entry_count(&self) -> u64; fn sync<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; }
Expand description

Async storage backend for a cache.

Implement this trait to provide a custom caching layer. The type parameter V is the cached value type.

§Object safety

CacheBackend<V> is object-safe when used with async_trait, so TypedCache<V> can hold any backend behind Arc<dyn CacheBackend<V>>.

Required Methods§

Source

fn get<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Option<V>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Return the cached value for key, or None on a miss.

Source

fn insert<'life0, 'async_trait>( &'life0 self, key: String, value: V, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Store value under key.

Source

fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove all entries.

Source

fn entry_count(&self) -> u64

Return the number of live entries (best-effort; may return 0 for some backends).

Source

fn sync<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Flush any pending internal tasks (useful for testing).

Implementors§

Source§

impl<V> CacheBackend<V> for RedisCache<V>
where V: Serialize + DeserializeOwned + Send + Sync + 'static,

Source§

impl<V> CacheBackend<V> for SqliteCache<V>
where V: Serialize + DeserializeOwned + Send + Sync + 'static,

Source§

impl<V: Clone + Send + Sync + 'static> CacheBackend<V> for MemoryCache<V>