pub struct CacheService { /* private fields */ }Expand description
缓存服务 (提供泛型封装)
Implementations§
Source§impl CacheService
impl CacheService
Sourcepub fn new(backend: Box<dyn CacheBackend>) -> Self
pub fn new(backend: Box<dyn CacheBackend>) -> Self
从后端创建缓存服务
Sourcepub async fn get<T: DeserializeOwned>(
&self,
key: &str,
) -> CacheResult<Option<T>>
pub async fn get<T: DeserializeOwned>( &self, key: &str, ) -> CacheResult<Option<T>>
获取缓存值
Sourcepub async fn set<T: Serialize + ?Sized>(
&self,
key: &str,
value: &T,
ttl: Option<Duration>,
) -> CacheResult<()>
pub async fn set<T: Serialize + ?Sized>( &self, key: &str, value: &T, ttl: Option<Duration>, ) -> CacheResult<()>
设置缓存值
Sourcepub async fn delete(&self, key: &str) -> CacheResult<bool>
pub async fn delete(&self, key: &str) -> CacheResult<bool>
删除缓存键
Sourcepub async fn exists(&self, key: &str) -> CacheResult<bool>
pub async fn exists(&self, key: &str) -> CacheResult<bool>
检查键是否存在
Sourcepub async fn mget<T: DeserializeOwned>(
&self,
keys: &[&str],
) -> CacheResult<Vec<Option<T>>>
pub async fn mget<T: DeserializeOwned>( &self, keys: &[&str], ) -> CacheResult<Vec<Option<T>>>
批量获取缓存值
Sourcepub async fn mset<T: Serialize + ?Sized>(
&self,
items: &[(&str, &T)],
ttl: Option<Duration>,
) -> CacheResult<()>
pub async fn mset<T: Serialize + ?Sized>( &self, items: &[(&str, &T)], ttl: Option<Duration>, ) -> CacheResult<()>
批量设置缓存值
Sourcepub async fn mdelete(&self, keys: &[&str]) -> CacheResult<u64>
pub async fn mdelete(&self, keys: &[&str]) -> CacheResult<u64>
批量删除缓存键
Sourcepub async fn clear(&self) -> CacheResult<()>
pub async fn clear(&self) -> CacheResult<()>
清空缓存
Sourcepub fn config(&self) -> &CacheConfig
pub fn config(&self) -> &CacheConfig
获取配置
Auto Trait Implementations§
impl Freeze for CacheService
impl !RefUnwindSafe for CacheService
impl Send for CacheService
impl Sync for CacheService
impl Unpin for CacheService
impl UnsafeUnpin for CacheService
impl !UnwindSafe for CacheService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more