pub trait Cache: Send + Sync {
// Required methods
fn set<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
value: &'life2 T,
ttl_seconds: Option<u64>,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>
where T: Serialize + Send + Sync + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<Option<T>>> + Send + 'async_trait>>
where T: for<'de> Deserialize<'de> + Send + Sync + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn expire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
ttl_seconds: u64,
) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<Option<u64>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheResult<CacheStats>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn mget<'life0, 'async_trait, T>(
&'life0 self,
keys: Vec<String>,
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<(String, Option<T>)>>> + Send + 'async_trait>>
where T: for<'de> Deserialize<'de> + Send + Sync + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn mset<'life0, 'async_trait, T>(
&'life0 self,
entries: Vec<(String, T, Option<u64>)>,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>
where T: Serialize + Send + Sync + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn mdelete<'life0, 'async_trait>(
&'life0 self,
keys: Vec<String>,
) -> Pin<Box<dyn Future<Output = CacheResult<u64>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Generic cache trait
Required Methods§
Sourcefn set<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
value: &'life2 T,
ttl_seconds: Option<u64>,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>
fn set<'life0, 'life1, 'life2, 'async_trait, T>( &'life0 self, key: &'life1 str, value: &'life2 T, ttl_seconds: Option<u64>, ) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>
Store value in cache
Sourcefn get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<Option<T>>> + Send + 'async_trait>>where
T: for<'de> Deserialize<'de> + Send + Sync + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<Option<T>>> + Send + 'async_trait>>where
T: for<'de> Deserialize<'de> + Send + Sync + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get value from cache
Sourcefn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Delete value from cache
Sourcefn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Check if key exists in cache
Sourcefn expire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
ttl_seconds: u64,
) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn expire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
ttl_seconds: u64,
) -> Pin<Box<dyn Future<Output = CacheResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Set TTL for existing key
Sourcefn ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<Option<u64>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<Option<u64>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get TTL for key (None if key doesn’t exist or has no expiration)
Sourcefn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Clear all cache entries
Sourcefn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheResult<CacheStats>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stats<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheResult<CacheStats>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Get cache statistics
Sourcefn mget<'life0, 'async_trait, T>(
&'life0 self,
keys: Vec<String>,
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<(String, Option<T>)>>> + Send + 'async_trait>>where
T: for<'de> Deserialize<'de> + Send + Sync + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
fn mget<'life0, 'async_trait, T>(
&'life0 self,
keys: Vec<String>,
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<(String, Option<T>)>>> + Send + 'async_trait>>where
T: for<'de> Deserialize<'de> + Send + Sync + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
Get multiple values from cache
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".