pub struct Cache { /* private fields */ }Expand description
通用缓存门面。
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn new(client: RedisClient, config: CacheConfig) -> Self
pub fn new(client: RedisClient, config: CacheConfig) -> Self
创建缓存门面。
Sourcepub fn client(&self) -> &RedisClient
pub fn client(&self) -> &RedisClient
底层 Redis 客户端(高级用法)。
Sourcepub fn config(&self) -> &CacheConfig
pub fn config(&self) -> &CacheConfig
当前配置。
Sourcepub async fn get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
pub async fn get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
读取缓存;miss 与缓存空值都返回 None。
Sourcepub async fn set_with_ttl<T: Serialize>(
&self,
key: &str,
value: &T,
ttl: Duration,
) -> Result<()>
pub async fn set_with_ttl<T: Serialize>( &self, key: &str, value: &T, ttl: Duration, ) -> Result<()>
写入缓存并指定 TTL。
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Cache
impl !UnwindSafe for Cache
impl Forget for Cache
impl Freeze for Cache
impl Move for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnsafeUnpin for Cache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more