Trait CacheProvider

Source
pub trait CacheProvider: Send + Sync {
    // Required methods
    fn get<'life0, 'life1, 'async_trait, T>(
        &'life0 self,
        key: &'life1 (impl 'async_trait + CacheKey),
    ) -> Pin<Box<dyn Future<Output = Option<T>> + Send + 'async_trait>>
       where T: DeserializeOwned + Send + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn set<'life0, 'life1, 'life2, 'async_trait, T>(
        &'life0 self,
        key: &'life1 (impl 'async_trait + CacheKey),
        value: &'life2 T,
        ttl: Option<Duration>,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where T: Serialize + Send + Sync + 'async_trait,
             Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn remove<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 (impl 'async_trait + CacheKey),
    ) -> Pin<Box<dyn Future<Output = bool> + 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 = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn exists<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 (impl 'async_trait + CacheKey),
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn stats<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = CacheStats> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn set_enabled(&mut self, enabled: bool);
    fn is_enabled(&self) -> bool;
}
Expand description

Cache provider trait

This trait abstracts cache operations, allowing for different implementations (e.g., in-memory, Redis, mock for testing)

Required Methods§

Source

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

Get a value from the cache

Source

fn set<'life0, 'life1, 'life2, 'async_trait, T>( &'life0 self, key: &'life1 (impl 'async_trait + CacheKey), value: &'life2 T, ttl: Option<Duration>, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where T: Serialize + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Set a value in the cache with optional TTL

Source

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

Remove a value from the cache

Source

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

Clear all values from the cache

Source

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

Check if a key exists in the cache

Source

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

Get cache statistics

Source

fn set_enabled(&mut self, enabled: bool)

Set cache enabled/disabled state

Source

fn is_enabled(&self) -> bool

Check if cache is enabled

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§