pub trait CacheStore: Send + Sync {
// Required methods
fn read(&self, key: &str) -> Option<Value>;
fn write(&self, key: &str, value: Value, options: CacheOptions);
fn delete(&self, key: &str) -> bool;
fn exist(&self, key: &str) -> bool;
fn fetch(
&self,
key: &str,
options: CacheOptions,
f: impl FnOnce() -> Value,
) -> Value;
fn increment(&self, key: &str, amount: i64) -> Option<i64>;
fn decrement(&self, key: &str, amount: i64) -> Option<i64>;
fn clear(&self);
fn read_multi(&self, keys: &[&str]) -> HashMap<String, Value>;
fn write_multi(
&self,
entries: HashMap<String, Value>,
options: CacheOptions,
);
}Expand description
Shared behavior implemented by cache backends.
Required Methods§
Sourcefn write(&self, key: &str, value: Value, options: CacheOptions)
fn write(&self, key: &str, value: Value, options: CacheOptions)
Writes a value under key with the given options.
Sourcefn fetch(
&self,
key: &str,
options: CacheOptions,
f: impl FnOnce() -> Value,
) -> Value
fn fetch( &self, key: &str, options: CacheOptions, f: impl FnOnce() -> Value, ) -> Value
Reads a cached value or computes and stores it on a miss.
Sourcefn increment(&self, key: &str, amount: i64) -> Option<i64>
fn increment(&self, key: &str, amount: i64) -> Option<i64>
Increments an integer entry by amount.
Sourcefn decrement(&self, key: &str, amount: i64) -> Option<i64>
fn decrement(&self, key: &str, amount: i64) -> Option<i64>
Decrements an integer entry by amount.
Sourcefn read_multi(&self, keys: &[&str]) -> HashMap<String, Value>
fn read_multi(&self, keys: &[&str]) -> HashMap<String, Value>
Reads many keys at once, omitting misses.
Sourcefn write_multi(&self, entries: HashMap<String, Value>, options: CacheOptions)
fn write_multi(&self, entries: HashMap<String, Value>, options: CacheOptions)
Writes many key/value pairs with shared options.
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.