Trait Cache

Source
pub trait Cache<T: Clone>: Send + Sync {
    // Required methods
    fn get_with<'life0, 'async_trait>(
        &'life0 self,
        key: String,
        future: Box<dyn Future<Output = T> + Send>,
    ) -> Pin<Box<dyn Future<Output = Result<T, CacheError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn remove<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

A cache.

Required Methods§

Source

fn get_with<'life0, 'async_trait>( &'life0 self, key: String, future: Box<dyn Future<Output = T> + Send>, ) -> Pin<Box<dyn Future<Output = Result<T, CacheError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gets a cached value.

If a cached value is not found, it awaits the given future and sets its resulting value into the cache and returns the value.

Source

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

Removes a cached value corresponding to the given key.

Implementors§

Source§

impl<T: Clone + Send + Sync + 'static> Cache<T> for MokaCache<T>

Source§

impl<T: Clone + Send + Sync> Cache<T> for MemoryCache<T>

Source§

impl<T: Clone + Serialize + for<'a> Deserialize<'a> + Send + Sync> Cache<T> for SledCache<T>