Skip to main content

CacheBackend

Trait CacheBackend 

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

Source

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.

Source

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.

Source

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.

Implementations on Foreign Types§

Source§

impl CacheBackend for Box<dyn Backend>

Source§

impl CacheBackend for Arc<SyncBackend>

Source§

impl CacheBackend for Arc<UnsyncBackend>

Implementors§

Source§

impl CacheBackend for &dyn Backend

Source§

impl<L1, L2, O, R, W> CacheBackend for CompositionBackend<L1, L2, O, R, W>
where L1: CacheBackend + Clone + Send + Sync + 'static, L2: CacheBackend + Clone + Send + Sync + 'static, O: Offload<'static>, R: CompositionReadPolicy, W: CompositionWritePolicy,