Trait cached::IOCached

source ·
pub trait IOCached<K, V> {
    type Error;

    // Required methods
    fn cache_get(&self, k: &K) -> Result<Option<V>, Self::Error>;
    fn cache_set(&self, k: K, v: V) -> Result<Option<V>, Self::Error>;
    fn cache_remove(&self, k: &K) -> Result<Option<V>, Self::Error>;
    fn cache_set_refresh(&mut self, refresh: bool) -> bool;

    // Provided methods
    fn cache_lifespan(&self) -> Option<u64> { ... }
    fn cache_set_lifespan(&mut self, _seconds: u64) -> Option<u64> { ... }
    fn cache_unset_lifespan(&mut self) -> Option<u64> { ... }
}
Expand description

Cache operations on an io-connected store

Required Associated Types§

Required Methods§

source

fn cache_get(&self, k: &K) -> Result<Option<V>, Self::Error>

Attempt to retrieve a cached value

§Errors

Should return Self::Error if the operation fails

source

fn cache_set(&self, k: K, v: V) -> Result<Option<V>, Self::Error>

Insert a key, value pair and return the previous value

§Errors

Should return Self::Error if the operation fails

source

fn cache_remove(&self, k: &K) -> Result<Option<V>, Self::Error>

Remove a cached value

§Errors

Should return Self::Error if the operation fails

source

fn cache_set_refresh(&mut self, refresh: bool) -> bool

Set the flag to control whether cache hits refresh the ttl of cached values, returns the old flag value

Provided Methods§

source

fn cache_lifespan(&self) -> Option<u64>

Return the lifespan of cached values (time to eviction)

source

fn cache_set_lifespan(&mut self, _seconds: u64) -> Option<u64>

Set the lifespan of cached values, returns the old value.

source

fn cache_unset_lifespan(&mut self) -> Option<u64>

Remove the lifespan for cached values, returns the old value.

For cache implementations that don’t support retaining values indefinitely, this method is a no-op.

Implementors§

source§

impl<K, V> IOCached<K, V> for DiskCache<K, V>

source§

impl<K, V> IOCached<K, V> for RedisCache<K, V>