pub trait CacheExt: CacheOps {
// Provided methods
fn get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + Send + 'async_trait>>
where T: 'async_trait + DeserializeOwned + Send,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn set<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
value: &'life2 T,
ttl: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where T: 'async_trait + Serialize + Send + Sync,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn set_l1_only<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
value: &'life2 T,
ttl: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where T: 'async_trait + Serialize + Send + Sync,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn set_l2_only<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
value: &'life2 T,
ttl: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where T: 'async_trait + Serialize + Send + Sync,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn get_or_fetch<'life0, 'life1, 'async_trait, T, F, Fut>(
&'life0 self,
key: &'life1 str,
ttl: Option<u64>,
fetch: F,
) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>
where T: DeserializeOwned + Serialize + Send + Sync + Clone + 'async_trait,
F: FnOnce() -> Fut + Send + 'async_trait,
Fut: Future<Output = Result<T>> + Send + 'async_trait,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn try_get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + Send + 'async_trait>>
where T: 'async_trait + DeserializeOwned + Send,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn remove<'life0, 'life1, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + Send + 'async_trait>>
where T: 'async_trait + DeserializeOwned + Send,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn contains<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
缓存扩展特征
提供类型安全的缓存操作接口
Provided Methods§
Sourcefn get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Send,
Self: Sync + '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 = Result<Option<T>>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Send,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
获取缓存值(反序列化)
Sourcefn set<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
value: &'life2 T,
ttl: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
fn set<'life0, 'life1, 'life2, 'async_trait, T>( &'life0 self, key: &'life1 str, value: &'life2 T, ttl: Option<u64>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
设置缓存值(序列化)
Sourcefn set_l1_only<'life0, 'life1, 'life2, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
value: &'life2 T,
ttl: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
fn set_l1_only<'life0, 'life1, 'life2, 'async_trait, T>( &'life0 self, key: &'life1 str, value: &'life2 T, ttl: Option<u64>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
仅设置 L1 缓存(如果支持)
fn set_l2_only<'life0, 'life1, 'life2, 'async_trait, T>( &'life0 self, key: &'life1 str, value: &'life2 T, ttl: Option<u64>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
Sourcefn get_or_fetch<'life0, 'life1, 'async_trait, T, F, Fut>(
&'life0 self,
key: &'life1 str,
ttl: Option<u64>,
fetch: F,
) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>
fn get_or_fetch<'life0, 'life1, 'async_trait, T, F, Fut>( &'life0 self, key: &'life1 str, ttl: Option<u64>, fetch: F, ) -> Pin<Box<dyn Future<Output = Result<T>> + Send + 'async_trait>>
Sourcefn try_get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Send,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn try_get<'life0, 'life1, 'async_trait, T>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Send,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
尝试获取,如果不存在返回 None(不触发 fetch)
这是一个便捷方法,避免使用 Option 处理
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.