Skip to main content

CacheStore

Trait CacheStore 

Source
pub trait CacheStore:
    Send
    + Sync
    + Debug {
Show 16 methods // Required methods fn get<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>, CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn set<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, value: &'life2 str, ttl_seconds: Option<u64>, ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: '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 Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn increment<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, by: i64, ) -> Pin<Box<dyn Future<Output = Result<i64, CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn name(&self) -> &str; // Provided methods fn forever<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, value: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn has<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool, CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn pull<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<String>, CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn decrement<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, by: i64, ) -> Pin<Box<dyn Future<Output = Result<i64, CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn touch<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ttl_seconds: u64, ) -> Pin<Box<dyn Future<Output = Result<bool, CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn many<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, keys: &'life1 [&'life2 str], ) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Option<String>>, CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait { ... } fn set_many<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, items: &'life1 [(&'life2 str, &'life3 str)], ttl_seconds: Option<u64>, ) -> Pin<Box<dyn Future<Output = Result<(), CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait { ... } fn remember<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ttl_seconds: u64, callback: Box<dyn FnOnce() -> Pin<Box<dyn Future<Output = String> + Send>> + Send>, ) -> Pin<Box<dyn Future<Output = Result<String, CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn remember_forever<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, callback: Box<dyn FnOnce() -> Pin<Box<dyn Future<Output = String> + Send>> + Send>, ) -> Pin<Box<dyn Future<Output = Result<String, CacheError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn as_lock_store(&self) -> Option<Arc<dyn LockStore>> { ... }
}
Expand description

Trait for cache store implementations.

Required Methods§

Source

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

Retrieve a value by key. Returns None if missing or expired.

Source

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

Store a value with an optional TTL in seconds.

Source

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

Delete a key. Returns true if the key existed.

Source

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

Remove all items from the store.

Source

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

Increment a numeric value. Returns the new value.

Source

fn name(&self) -> &str

Provided Methods§

Source

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

Store a value permanently (or for a very long time).

Source

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

Check if a key exists and is not expired.

Source

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

Get and delete a key atomically.

Source

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

Decrement a numeric value. Returns the new value.

Source

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

Extend the TTL of an existing key without re-fetching its value. Returns false if the key does not exist or is expired.

Source

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

Retrieve multiple keys at once.

Source

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

Store multiple items at once with the same TTL.

Source

fn remember<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ttl_seconds: u64, callback: Box<dyn FnOnce() -> Pin<Box<dyn Future<Output = String> + Send>> + Send>, ) -> Pin<Box<dyn Future<Output = Result<String, CacheError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get or store a value using a boxed callback.

Source

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

Get or store forever using a boxed callback.

Source

fn as_lock_store(&self) -> Option<Arc<dyn LockStore>>

Return a LockStore view of this store when it supports atomic locks (array, redis). Stores without lock support return None.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§