Skip to main content

CacheServiceExt

Trait CacheServiceExt 

Source
pub trait CacheServiceExt<K, V>: Sized {
    // Required methods
    fn get(
        &self,
        key: &K,
    ) -> impl Future<Output = Result<Option<CacheEntry<V>>, Error>> + Send;
    fn insert(
        &self,
        key: K,
        entry: CacheEntry<V>,
    ) -> impl Future<Output = Result<(), Error>> + Send;
    fn invalidate(
        &self,
        key: &K,
    ) -> impl Future<Output = Result<(), Error>> + Send;
    fn clear(&self) -> impl Future<Output = Result<(), Error>> + Send;
}
Available on crate feature service only.
Expand description

Extension trait providing ergonomic cache methods for any Service<CacheOperation>.

This allows middleware-wrapped cache services to be used with the same simple API as a direct Cache.

Required Methods§

Source

fn get( &self, key: &K, ) -> impl Future<Output = Result<Option<CacheEntry<V>>, Error>> + Send

Retrieves a value from the cache.

Source

fn insert( &self, key: K, entry: CacheEntry<V>, ) -> impl Future<Output = Result<(), Error>> + Send

Inserts a value into the cache.

Source

fn invalidate(&self, key: &K) -> impl Future<Output = Result<(), Error>> + Send

Invalidates (removes) a value from the cache.

Source

fn clear(&self) -> impl Future<Output = Result<(), Error>> + Send

Clears all entries from the cache.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<K, V, S> CacheServiceExt<K, V> for S
where K: Clone + Send + Sync, V: Clone + Send + Sync, S: Service<CacheOperation<K, V>, Out = Result<CacheResponse<V>, Error>> + Send + Sync,