CacheBackend

Trait CacheBackend 

Source
pub trait CacheBackend:
    Send
    + Sync
    + 'static {
Show 13 methods // Required methods fn get<T>( &self, key: &CacheKey, ) -> impl Future<Output = CacheResult<Option<T>>> + Send where T: DeserializeOwned; fn set<T>( &self, key: &CacheKey, value: &T, ttl: Option<Duration>, ) -> impl Future<Output = CacheResult<()>> + Send where T: Serialize + Sync; fn delete( &self, key: &CacheKey, ) -> impl Future<Output = CacheResult<bool>> + Send; fn exists( &self, key: &CacheKey, ) -> impl Future<Output = CacheResult<bool>> + Send; fn invalidate_pattern( &self, pattern: &KeyPattern, ) -> impl Future<Output = CacheResult<u64>> + Send; fn invalidate_tags( &self, tags: &[EntityTag], ) -> impl Future<Output = CacheResult<u64>> + Send; fn clear(&self) -> impl Future<Output = CacheResult<()>> + Send; fn len(&self) -> impl Future<Output = CacheResult<usize>> + Send; // Provided methods fn get_many<T>( &self, keys: &[CacheKey], ) -> impl Future<Output = CacheResult<Vec<Option<T>>>> + Send where T: DeserializeOwned + Send { ... } fn set_many<T>( &self, entries: &[(&CacheKey, &T)], ttl: Option<Duration>, ) -> impl Future<Output = CacheResult<()>> + Send where T: Serialize + Sync + Send { ... } fn delete_many( &self, keys: &[CacheKey], ) -> impl Future<Output = CacheResult<u64>> + Send { ... } fn is_empty(&self) -> impl Future<Output = CacheResult<bool>> + Send { ... } fn stats(&self) -> impl Future<Output = CacheResult<BackendStats>> + Send { ... }
}
Expand description

The core trait for cache backends.

This trait defines the interface that all cache backends must implement. It supports both synchronous and asynchronous operations.

Required Methods§

Source

fn get<T>( &self, key: &CacheKey, ) -> impl Future<Output = CacheResult<Option<T>>> + Send

Get a value from the cache.

Source

fn set<T>( &self, key: &CacheKey, value: &T, ttl: Option<Duration>, ) -> impl Future<Output = CacheResult<()>> + Send
where T: Serialize + Sync,

Set a value in the cache.

Source

fn delete( &self, key: &CacheKey, ) -> impl Future<Output = CacheResult<bool>> + Send

Delete a value from the cache.

Source

fn exists( &self, key: &CacheKey, ) -> impl Future<Output = CacheResult<bool>> + Send

Check if a key exists.

Source

fn invalidate_pattern( &self, pattern: &KeyPattern, ) -> impl Future<Output = CacheResult<u64>> + Send

Invalidate entries matching a pattern.

Source

fn invalidate_tags( &self, tags: &[EntityTag], ) -> impl Future<Output = CacheResult<u64>> + Send

Invalidate entries by tags.

Source

fn clear(&self) -> impl Future<Output = CacheResult<()>> + Send

Clear all entries.

Source

fn len(&self) -> impl Future<Output = CacheResult<usize>> + Send

Get the approximate number of entries.

Provided Methods§

Source

fn get_many<T>( &self, keys: &[CacheKey], ) -> impl Future<Output = CacheResult<Vec<Option<T>>>> + Send

Get multiple values at once.

Default implementation fetches sequentially. Override for batch optimization.

Source

fn set_many<T>( &self, entries: &[(&CacheKey, &T)], ttl: Option<Duration>, ) -> impl Future<Output = CacheResult<()>> + Send
where T: Serialize + Sync + Send,

Set multiple values at once.

Default implementation sets sequentially. Override for batch optimization.

Source

fn delete_many( &self, keys: &[CacheKey], ) -> impl Future<Output = CacheResult<u64>> + Send

Delete multiple keys at once.

Default implementation deletes sequentially. Override for batch optimization.

Source

fn is_empty(&self) -> impl Future<Output = CacheResult<bool>> + Send

Check if the cache is empty.

Source

fn stats(&self) -> impl Future<Output = CacheResult<BackendStats>> + Send

Get cache statistics if available.

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.

Implementors§