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§
sourcefn cache_set(&self, k: K, v: V) -> Result<Option<V>, Self::Error>
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
sourcefn cache_set_refresh(&mut self, refresh: bool) -> bool
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§
sourcefn cache_lifespan(&self) -> Option<u64>
fn cache_lifespan(&self) -> Option<u64>
Return the lifespan of cached values (time to eviction)
sourcefn cache_set_lifespan(&mut self, _seconds: u64) -> Option<u64>
fn cache_set_lifespan(&mut self, _seconds: u64) -> Option<u64>
Set the lifespan of cached values, returns the old value.
sourcefn cache_unset_lifespan(&mut self) -> Option<u64>
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.