Skip to main content

Backend

Trait Backend 

Source
pub trait Backend: Sync + Send {
    // Required methods
    fn read<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 CacheKey,
    ) -> Pin<Box<dyn Future<Output = Result<Option<CacheValue<Bytes>>, BackendError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn write<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 CacheKey,
        value: CacheValue<Bytes>,
    ) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn remove<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 CacheKey,
    ) -> Pin<Box<dyn Future<Output = Result<DeleteStatus, BackendError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn label(&self) -> BackendLabel { ... }
    fn value_format(&self) -> &dyn Format { ... }
    fn key_format(&self) -> &CacheKeyFormat { ... }
    fn compressor(&self) -> &dyn Compressor { ... }
}
Expand description

Low-level cache storage trait for raw byte operations.

Implement this trait to create a custom cache backend. The trait operates on raw bytes (CacheValue<Raw>), with serialization handled by CacheBackend.

§Dyn-Compatibility

This trait is dyn-compatible. Blanket implementations are provided for:

Required Methods§

Source

fn read<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<Option<CacheValue<Bytes>>, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Read raw cached data by key.

Returns Ok(Some(value)) on hit, Ok(None) on miss.

Source

fn write<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, value: CacheValue<Bytes>, ) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Write raw data to cache.

Source

fn remove<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<DeleteStatus, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Remove data from cache.

Provided Methods§

Source

fn label(&self) -> BackendLabel

Backend label for metrics and source path composition.

Used to build hierarchical paths like "composition.moka" in CompositionBackend.

Source

fn value_format(&self) -> &dyn Format

Serialization format for cached values. Default: BincodeFormat.

Source

fn key_format(&self) -> &CacheKeyFormat

Key serialization format. Default: CacheKeyFormat::Bitcode.

Source

fn compressor(&self) -> &dyn Compressor

Compressor for cached values. Default: PassthroughCompressor.

Trait Implementations§

Source§

impl Backend for &dyn Backend

Source§

fn read<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<Option<CacheValue<Bytes>>, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, &dyn Backend: 'async_trait,

Read raw cached data by key. Read more
Source§

fn write<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, value: CacheValue<Bytes>, ) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, &dyn Backend: 'async_trait,

Write raw data to cache.
Source§

fn remove<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<DeleteStatus, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, &dyn Backend: 'async_trait,

Remove data from cache.
Source§

fn label(&self) -> BackendLabel

Backend label for metrics and source path composition. Read more
Source§

fn value_format(&self) -> &dyn Format

Serialization format for cached values. Default: BincodeFormat.
Source§

fn key_format(&self) -> &CacheKeyFormat

Key serialization format. Default: CacheKeyFormat::Bitcode.
Source§

fn compressor(&self) -> &dyn Compressor

Compressor for cached values. Default: PassthroughCompressor.
Source§

impl Backend for Box<dyn Backend>

Source§

fn read<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<Option<CacheValue<Bytes>>, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn Backend>: 'async_trait,

Read raw cached data by key. Read more
Source§

fn write<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, value: CacheValue<Bytes>, ) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn Backend>: 'async_trait,

Write raw data to cache.
Source§

fn remove<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<DeleteStatus, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn Backend>: 'async_trait,

Remove data from cache.
Source§

fn label(&self) -> BackendLabel

Backend label for metrics and source path composition. Read more
Source§

fn value_format(&self) -> &dyn Format

Serialization format for cached values. Default: BincodeFormat.
Source§

fn key_format(&self) -> &CacheKeyFormat

Key serialization format. Default: CacheKeyFormat::Bitcode.
Source§

fn compressor(&self) -> &dyn Compressor

Compressor for cached values. Default: PassthroughCompressor.
Source§

impl CacheBackend for &dyn Backend

Source§

fn get<T>( &self, key: &CacheKey, ctx: &mut SmallBox<dyn Context, S4>, ) -> impl Future<Output = Result<Option<CacheValue<<T as CacheableResponse>::Cached>>, BackendError>> + Send

Retrieve a typed value from cache. Read more
Source§

fn set<T>( &self, key: &CacheKey, value: &CacheValue<<T as CacheableResponse>::Cached>, ctx: &mut SmallBox<dyn Context, S4>, ) -> impl Future<Output = Result<(), BackendError>> + Send

Store a typed value in cache. Read more
Source§

fn delete( &self, key: &CacheKey, _ctx: &mut SmallBox<dyn Context, S4>, ) -> impl Future<Output = Result<DeleteStatus, BackendError>> + Send

Delete a value from cache. Read more
Source§

impl CacheBackend for Box<dyn Backend>

Source§

fn get<T>( &self, key: &CacheKey, ctx: &mut SmallBox<dyn Context, S4>, ) -> impl Future<Output = Result<Option<CacheValue<<T as CacheableResponse>::Cached>>, BackendError>> + Send

Retrieve a typed value from cache. Read more
Source§

fn set<T>( &self, key: &CacheKey, value: &CacheValue<<T as CacheableResponse>::Cached>, ctx: &mut SmallBox<dyn Context, S4>, ) -> impl Future<Output = Result<(), BackendError>> + Send

Store a typed value in cache. Read more
Source§

fn delete( &self, key: &CacheKey, _ctx: &mut SmallBox<dyn Context, S4>, ) -> impl Future<Output = Result<DeleteStatus, BackendError>> + Send

Delete a value from cache. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Backend for Arc<dyn Backend + Send>

Source§

fn read<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<Option<CacheValue<Bytes>>, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Arc<dyn Backend + Send>: 'async_trait,

Source§

fn write<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, value: CacheValue<Bytes>, ) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Arc<dyn Backend + Send>: 'async_trait,

Source§

fn remove<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<DeleteStatus, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Arc<dyn Backend + Send>: 'async_trait,

Source§

fn label(&self) -> BackendLabel

Source§

fn value_format(&self) -> &dyn Format

Source§

fn key_format(&self) -> &CacheKeyFormat

Source§

fn compressor(&self) -> &dyn Compressor

Source§

impl Backend for Arc<dyn Backend + Sync + Send>

Source§

fn read<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<Option<CacheValue<Bytes>>, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Arc<dyn Backend + Sync + Send>: 'async_trait,

Source§

fn write<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, value: CacheValue<Bytes>, ) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Arc<dyn Backend + Sync + Send>: 'async_trait,

Source§

fn remove<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<DeleteStatus, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Arc<dyn Backend + Sync + Send>: 'async_trait,

Source§

fn label(&self) -> BackendLabel

Source§

fn value_format(&self) -> &dyn Format

Source§

fn key_format(&self) -> &CacheKeyFormat

Source§

fn compressor(&self) -> &dyn Compressor

Source§

impl Backend for Box<dyn Backend>

Source§

fn read<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<Option<CacheValue<Bytes>>, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn Backend>: 'async_trait,

Source§

fn write<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, value: CacheValue<Bytes>, ) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn Backend>: 'async_trait,

Source§

fn remove<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<DeleteStatus, BackendError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Box<dyn Backend>: 'async_trait,

Source§

fn label(&self) -> BackendLabel

Source§

fn value_format(&self) -> &dyn Format

Source§

fn key_format(&self) -> &CacheKeyFormat

Source§

fn compressor(&self) -> &dyn Compressor

Implementors§

Source§

impl Backend for &dyn Backend

Source§

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