pub trait CacheBackend: Backend {
// Provided methods
fn get<T>(
&self,
key: &CacheKey,
ctx: &mut BoxContext,
) -> impl Future<Output = BackendResult<Option<CacheValue<T::Cached>>>> + Send
where T: CacheableResponse,
T::Cached: Cacheable { ... }
fn set<T>(
&self,
key: &CacheKey,
value: &CacheValue<T::Cached>,
ctx: &mut BoxContext,
) -> impl Future<Output = BackendResult<()>> + Send
where T: CacheableResponse,
T::Cached: Cacheable { ... }
fn delete(
&self,
key: &CacheKey,
_ctx: &mut BoxContext,
) -> impl Future<Output = BackendResult<DeleteStatus>> + Send { ... }
}Expand description
High-level cache backend trait with typed operations.
This trait provides typed get, set, and delete operations that handle
serialization/deserialization and context tracking. The context is passed
as a mutable reference and updated in-place during operations.
Automatically implemented for all Backend implementations.
Typically, you don’t need to implement this trait yourself - the default implementation handles serialization, compression, and metrics automatically.
If you do provide a custom implementation, be aware that when your backend
is used as a trait object (dyn Backend, Box<dyn Backend>, etc.), the
blanket implementation will be used instead of your custom one.
Provided Methods§
Sourcefn get<T>(
&self,
key: &CacheKey,
ctx: &mut BoxContext,
) -> impl Future<Output = BackendResult<Option<CacheValue<T::Cached>>>> + Send
fn get<T>( &self, key: &CacheKey, ctx: &mut BoxContext, ) -> impl Future<Output = BackendResult<Option<CacheValue<T::Cached>>>> + Send
Retrieve a typed value from cache.
Handles decompression and deserialization automatically using the
backend’s configured Format and Compressor.
Sourcefn set<T>(
&self,
key: &CacheKey,
value: &CacheValue<T::Cached>,
ctx: &mut BoxContext,
) -> impl Future<Output = BackendResult<()>> + Send
fn set<T>( &self, key: &CacheKey, value: &CacheValue<T::Cached>, ctx: &mut BoxContext, ) -> impl Future<Output = BackendResult<()>> + Send
Store a typed value in cache.
Handles serialization and compression automatically using the
backend’s configured Format and Compressor.
Sourcefn delete(
&self,
key: &CacheKey,
_ctx: &mut BoxContext,
) -> impl Future<Output = BackendResult<DeleteStatus>> + Send
fn delete( &self, key: &CacheKey, _ctx: &mut BoxContext, ) -> impl Future<Output = BackendResult<DeleteStatus>> + Send
Delete a value from cache.
Delegates to Backend::remove.
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.