CacheBackend

Trait CacheBackend 

Source
pub trait CacheBackend:
    Send
    + Sync
    + 'static {
    // Required methods
    fn get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<CacheEntry<Vec<u8>>>, CacheError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn set<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        value: Vec<u8>,
        options: &'life2 CacheOptions,
    ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, CacheError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn exists<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, CacheError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn delete_many<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        keys: &'life1 [&'life2 str],
    ) -> Pin<Box<dyn Future<Output = Result<u64, CacheError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn get_many<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        keys: &'life1 [&'life2 str],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Option<CacheEntry<Vec<u8>>>>, CacheError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn set_many<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        entries: &'life1 [(&'life2 str, Vec<u8>, &'life3 CacheOptions)],
    ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             Self: 'async_trait;
    fn clear<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn stats<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<CacheStats, CacheError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn len<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<usize, CacheError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;

    // Provided method
    fn is_empty<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<bool, CacheError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

Core trait for all cache storage backends

This trait defines the operations that any cache backend must support. Implementations include in-memory caches, Redis, and multi-tier backends.

Required Methods§

Source

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

Get a value from the cache

Returns None if the key doesn’t exist or has expired.

Source

fn set<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, value: Vec<u8>, options: &'life2 CacheOptions, ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Set a value in the cache

Source

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

Delete a key from the cache

Returns true if the key existed and was deleted.

Source

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

Check if a key exists in the cache

Source

fn delete_many<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, keys: &'life1 [&'life2 str], ) -> Pin<Box<dyn Future<Output = Result<u64, CacheError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Delete multiple keys

Returns the number of keys that were deleted.

Source

fn get_many<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, keys: &'life1 [&'life2 str], ) -> Pin<Box<dyn Future<Output = Result<Vec<Option<CacheEntry<Vec<u8>>>>, CacheError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Get multiple keys at once

Returns a vector of results in the same order as the input keys.

Source

fn set_many<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, entries: &'life1 [(&'life2 str, Vec<u8>, &'life3 CacheOptions)], ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, Self: 'async_trait,

Set multiple entries at once

Source

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

Clear all entries from the cache

Source

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

Get cache statistics

Source

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

Get the number of entries in the cache

Provided Methods§

Source

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

Check if the cache is empty

Implementors§