Skip to main content

CacheStore

Trait CacheStore 

Source
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§

Source

fn read(&self, key: &str) -> Option<Value>

Reads a cached value for key.

Source

fn write(&self, key: &str, value: Value, options: CacheOptions)

Writes a value under key with the given options.

Source

fn delete(&self, key: &str) -> bool

Deletes key, returning true when an entry existed.

Source

fn exist(&self, key: &str) -> bool

Returns true when a live entry exists for key.

Source

fn fetch( &self, key: &str, options: CacheOptions, f: impl FnOnce() -> Value, ) -> Value

Reads a cached value or computes and stores it on a miss.

Source

fn increment(&self, key: &str, amount: i64) -> Option<i64>

Increments an integer entry by amount.

Source

fn decrement(&self, key: &str, amount: i64) -> Option<i64>

Decrements an integer entry by amount.

Source

fn clear(&self)

Removes all entries from the store.

Source

fn read_multi(&self, keys: &[&str]) -> HashMap<String, Value>

Reads many keys at once, omitting misses.

Source

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.

Implementors§