Skip to main content

CacheExt

Trait CacheExt 

Source
pub trait CacheExt {
    // Required methods
    fn get<T: DeserializeOwned + Send>(
        &self,
        key: &str,
    ) -> impl Future<Output = Option<T>> + Send;
    fn set<T: Serialize + Send + Sync>(
        &self,
        key: &str,
        value: &T,
        ttl_secs: Option<u64>,
    ) -> impl Future<Output = ()> + Send;
    fn take<T: DeserializeOwned + Send>(
        &self,
        key: &str,
    ) -> impl Future<Output = Option<T>> + Send;
}
Expand description

Convenience methods for JSON serialization and deserialization.

Required Methods§

Source

fn get<T: DeserializeOwned + Send>( &self, key: &str, ) -> impl Future<Output = Option<T>> + Send

Reads and deserializes a JSON value from the cache.

Source

fn set<T: Serialize + Send + Sync>( &self, key: &str, value: &T, ttl_secs: Option<u64>, ) -> impl Future<Output = ()> + Send

Serializes and writes a JSON value to the cache.

Source

fn take<T: DeserializeOwned + Send>( &self, key: &str, ) -> impl Future<Output = Option<T>> + Send

Atomically reads, removes, and deserializes a JSON value from the cache.

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§