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§
Sourcefn get<T>(
&self,
key: &CacheKey,
) -> impl Future<Output = CacheResult<Option<T>>> + Sendwhere
T: DeserializeOwned,
fn get<T>(
&self,
key: &CacheKey,
) -> impl Future<Output = CacheResult<Option<T>>> + Sendwhere
T: DeserializeOwned,
Get a value from the cache.
Sourcefn set<T>(
&self,
key: &CacheKey,
value: &T,
ttl: Option<Duration>,
) -> impl Future<Output = CacheResult<()>> + Send
fn set<T>( &self, key: &CacheKey, value: &T, ttl: Option<Duration>, ) -> impl Future<Output = CacheResult<()>> + Send
Set a value in the cache.
Sourcefn delete(
&self,
key: &CacheKey,
) -> impl Future<Output = CacheResult<bool>> + Send
fn delete( &self, key: &CacheKey, ) -> impl Future<Output = CacheResult<bool>> + Send
Delete a value from the cache.
Sourcefn exists(
&self,
key: &CacheKey,
) -> impl Future<Output = CacheResult<bool>> + Send
fn exists( &self, key: &CacheKey, ) -> impl Future<Output = CacheResult<bool>> + Send
Check if a key exists.
Sourcefn invalidate_pattern(
&self,
pattern: &KeyPattern,
) -> impl Future<Output = CacheResult<u64>> + Send
fn invalidate_pattern( &self, pattern: &KeyPattern, ) -> impl Future<Output = CacheResult<u64>> + Send
Invalidate entries matching a pattern.
Invalidate entries by tags.
Provided Methods§
Sourcefn get_many<T>(
&self,
keys: &[CacheKey],
) -> impl Future<Output = CacheResult<Vec<Option<T>>>> + Sendwhere
T: DeserializeOwned + Send,
fn get_many<T>(
&self,
keys: &[CacheKey],
) -> impl Future<Output = CacheResult<Vec<Option<T>>>> + Sendwhere
T: DeserializeOwned + Send,
Get multiple values at once.
Default implementation fetches sequentially. Override for batch optimization.
Sourcefn set_many<T>(
&self,
entries: &[(&CacheKey, &T)],
ttl: Option<Duration>,
) -> impl Future<Output = CacheResult<()>> + Send
fn set_many<T>( &self, entries: &[(&CacheKey, &T)], ttl: Option<Duration>, ) -> impl Future<Output = CacheResult<()>> + Send
Set multiple values at once.
Default implementation sets sequentially. Override for batch optimization.
Sourcefn delete_many(
&self,
keys: &[CacheKey],
) -> impl Future<Output = CacheResult<u64>> + Send
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.
Sourcefn is_empty(&self) -> impl Future<Output = CacheResult<bool>> + Send
fn is_empty(&self) -> impl Future<Output = CacheResult<bool>> + Send
Check if the cache is empty.
Sourcefn stats(&self) -> impl Future<Output = CacheResult<BackendStats>> + Send
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.