pub trait CacheStore:
Send
+ Sync
+ 'static {
// Required methods
fn get<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Vec<u8>>>>;
fn set(
&self,
key: String,
value: Vec<u8>,
ttl: Option<Duration>,
) -> BoxFuture<'_, Result<()>>;
fn delete<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<()>>;
fn clear(&self) -> BoxFuture<'_, Result<()>>;
}Expand description
A cache backend that stores opaque byte values under string keys.
The Cache handle serializes typed values to bytes and talks
to a store through this trait, so any backend (in-memory, Redis) works the same
from a handler’s point of view. The trait is object-safe: a [Cache] holds an
Arc<dyn CacheStore>.
TTL convention: None keeps the entry until the store evicts it (no explicit
expiry); Some(duration) expires the entry after duration. A zero duration
is normalized to None (“never expire”) by the Cache handle
before it reaches the store.
Required Methods§
Sourcefn get<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Vec<u8>>>>
fn get<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Vec<u8>>>>
Returns the bytes stored under key, or None if absent or expired.
Sourcefn set(
&self,
key: String,
value: Vec<u8>,
ttl: Option<Duration>,
) -> BoxFuture<'_, Result<()>>
fn set( &self, key: String, value: Vec<u8>, ttl: Option<Duration>, ) -> BoxFuture<'_, Result<()>>
Stores value under key, expiring it after ttl when set.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".