Skip to main content

CacheExt

Trait CacheExt 

Source
pub trait CacheExt: Cache {
    // Provided methods
    fn get_or_set<'life0, 'life1, 'async_trait, F, Fut>(
        &'life0 self,
        key: &'life1 str,
        ttl: Option<Duration>,
        f: F,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, CacheError>> + Send + 'async_trait>>
       where F: FnOnce() -> Fut + Send + 'async_trait,
             Fut: Future<Output = Result<Vec<u8>, CacheError>> + Send + 'async_trait,
             Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn get_or_set_json<'life0, 'life1, 'async_trait, T, F, Fut>(
        &'life0 self,
        key: &'life1 str,
        ttl: Option<Duration>,
        f: F,
    ) -> Pin<Box<dyn Future<Output = Result<T, CacheError>> + Send + 'async_trait>>
       where T: Serialize + DeserializeOwned + Send + 'async_trait,
             F: FnOnce() -> Fut + Send + 'async_trait,
             Fut: Future<Output = Result<T, CacheError>> + Send + 'async_trait,
             Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Extension trait providing convenient get_or_set helpers on any Cache.

Provided Methods§

Source

fn get_or_set<'life0, 'life1, 'async_trait, F, Fut>( &'life0 self, key: &'life1 str, ttl: Option<Duration>, f: F, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, CacheError>> + Send + 'async_trait>>
where F: FnOnce() -> Fut + Send + 'async_trait, Fut: Future<Output = Result<Vec<u8>, CacheError>> + Send + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves key if cached; otherwise executes f, caches the result under key, and returns it.

Source

fn get_or_set_json<'life0, 'life1, 'async_trait, T, F, Fut>( &'life0 self, key: &'life1 str, ttl: Option<Duration>, f: F, ) -> Pin<Box<dyn Future<Output = Result<T, CacheError>> + Send + 'async_trait>>
where T: Serialize + DeserializeOwned + Send + 'async_trait, F: FnOnce() -> Fut + Send + 'async_trait, Fut: Future<Output = Result<T, CacheError>> + Send + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves and deserializes key from JSON; otherwise executes f, serializes to JSON, caches, and returns T.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<T: Cache + ?Sized> CacheExt for T