Skip to main content

Cache

Trait Cache 

Source
pub trait Cache: Send + Sync {
    // Required methods
    fn set<'life0, 'life1, 'life2, 'async_trait, T>(
        &'life0 self,
        key: &'life1 str,
        value: &'life2 T,
        ttl_seconds: Option<u64>,
    ) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>
       where T: Serialize + Send + Sync + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn get<'life0, 'life1, 'async_trait, T>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = CacheResult<Option<T>>> + Send + 'async_trait>>
       where T: for<'de> Deserialize<'de> + Send + Sync + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn exists<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn expire<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        ttl_seconds: u64,
    ) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn ttl<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = CacheResult<Option<u64>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn clear<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stats<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = CacheResult<CacheStats>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn mget<'life0, 'async_trait, T>(
        &'life0 self,
        keys: Vec<String>,
    ) -> Pin<Box<dyn Future<Output = CacheResult<Vec<(String, Option<T>)>>> + Send + 'async_trait>>
       where T: for<'de> Deserialize<'de> + Send + Sync + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait;
    fn mset<'life0, 'async_trait, T>(
        &'life0 self,
        entries: Vec<(String, T, Option<u64>)>,
    ) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>
       where T: Serialize + Send + Sync + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait;
    fn mdelete<'life0, 'async_trait>(
        &'life0 self,
        keys: Vec<String>,
    ) -> Pin<Box<dyn Future<Output = CacheResult<u64>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Generic cache trait

Required Methods§

Source

fn set<'life0, 'life1, 'life2, 'async_trait, T>( &'life0 self, key: &'life1 str, value: &'life2 T, ttl_seconds: Option<u64>, ) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>
where T: Serialize + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Store value in cache

Source

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

Get value from cache

Source

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

Delete value from cache

Source

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

Check if key exists in cache

Source

fn expire<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ttl_seconds: u64, ) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Set TTL for existing key

Source

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

Get TTL for key (None if key doesn’t exist or has no expiration)

Source

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

Clear all cache entries

Source

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

Get cache statistics

Source

fn mget<'life0, 'async_trait, T>( &'life0 self, keys: Vec<String>, ) -> Pin<Box<dyn Future<Output = CacheResult<Vec<(String, Option<T>)>>> + Send + 'async_trait>>
where T: for<'de> Deserialize<'de> + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Get multiple values from cache

Source

fn mset<'life0, 'async_trait, T>( &'life0 self, entries: Vec<(String, T, Option<u64>)>, ) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>
where T: Serialize + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Set multiple values in cache

Source

fn mdelete<'life0, 'async_trait>( &'life0 self, keys: Vec<String>, ) -> Pin<Box<dyn Future<Output = CacheResult<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Delete multiple keys from cache

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§