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:
&dyn BackendBox<dyn Backend>Arc<dyn Backend + Send>(UnsyncBackend)Arc<dyn Backend + Send + Sync>(SyncBackend)
Required Methods§
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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,
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§
Sourcefn label(&self) -> BackendLabel
fn label(&self) -> BackendLabel
Backend label for metrics and source path composition.
Used to build hierarchical paths like "composition.moka" in
CompositionBackend.
Sourcefn value_format(&self) -> &dyn Format
fn value_format(&self) -> &dyn Format
Serialization format for cached values. Default: BincodeFormat.
Sourcefn key_format(&self) -> &CacheKeyFormat
fn key_format(&self) -> &CacheKeyFormat
Key serialization format. Default: CacheKeyFormat::Bitcode.
Sourcefn compressor(&self) -> &dyn Compressor
fn compressor(&self) -> &dyn Compressor
Compressor for cached values. Default: PassthroughCompressor.
Trait Implementations§
Source§impl Backend for &dyn Backend
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,
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,
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,
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
fn label(&self) -> BackendLabel
Backend label for metrics and source path composition. Read more
Source§fn value_format(&self) -> &dyn Format
fn value_format(&self) -> &dyn Format
Serialization format for cached values. Default:
BincodeFormat.Source§fn key_format(&self) -> &CacheKeyFormat
fn key_format(&self) -> &CacheKeyFormat
Key serialization format. Default:
CacheKeyFormat::Bitcode.Source§fn compressor(&self) -> &dyn Compressor
fn compressor(&self) -> &dyn Compressor
Compressor for cached values. Default:
PassthroughCompressor.Source§impl Backend for Box<dyn Backend>
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>>
fn read<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<Option<CacheValue<Bytes>>, BackendError>> + Send + '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>>
fn write<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, value: CacheValue<Bytes>, ) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + '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>>
fn remove<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 CacheKey, ) -> Pin<Box<dyn Future<Output = Result<DeleteStatus, BackendError>> + Send + 'async_trait>>
Remove data from cache.
Source§fn label(&self) -> BackendLabel
fn label(&self) -> BackendLabel
Backend label for metrics and source path composition. Read more
Source§fn value_format(&self) -> &dyn Format
fn value_format(&self) -> &dyn Format
Serialization format for cached values. Default:
BincodeFormat.Source§fn key_format(&self) -> &CacheKeyFormat
fn key_format(&self) -> &CacheKeyFormat
Key serialization format. Default:
CacheKeyFormat::Bitcode.Source§fn compressor(&self) -> &dyn Compressor
fn compressor(&self) -> &dyn Compressor
Compressor for cached values. Default:
PassthroughCompressor.Source§impl CacheBackend for &dyn Backend
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
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§impl CacheBackend for Box<dyn Backend>
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
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