pub struct Cache<B: CacheBackend> { /* private fields */ }Expand description
High-level cache interface with type-safe operations
Implementations§
Source§impl<B: CacheBackend> Cache<B>
impl<B: CacheBackend> Cache<B>
Sourcepub fn with_default_ttl(backend: B, ttl: Duration) -> Self
pub fn with_default_ttl(backend: B, ttl: Duration) -> Self
Create a new cache instance with a default TTL
Sourcepub async fn get<T>(&self, key: &str) -> CacheResult<Option<T>>where
T: DeserializeOwned,
pub async fn get<T>(&self, key: &str) -> CacheResult<Option<T>>where
T: DeserializeOwned,
Get a typed value from the cache
Sourcepub async fn put<T>(
&self,
key: &str,
value: &T,
ttl: Duration,
) -> CacheResult<()>where
T: Serialize,
pub async fn put<T>(
&self,
key: &str,
value: &T,
ttl: Duration,
) -> CacheResult<()>where
T: Serialize,
Put a typed value in the cache
Sourcepub async fn put_default<T>(&self, key: &str, value: &T) -> CacheResult<()>where
T: Serialize,
pub async fn put_default<T>(&self, key: &str, value: &T) -> CacheResult<()>where
T: Serialize,
Put a typed value in the cache using default TTL
Sourcepub async fn forget(&self, key: &str) -> CacheResult<bool>
pub async fn forget(&self, key: &str) -> CacheResult<bool>
Remove a value from the cache
Sourcepub async fn exists(&self, key: &str) -> CacheResult<bool>
pub async fn exists(&self, key: &str) -> CacheResult<bool>
Check if a key exists
Sourcepub async fn flush(&self) -> CacheResult<()>
pub async fn flush(&self) -> CacheResult<()>
Clear all cache entries
Sourcepub async fn remember<T, F, Fut>(
&self,
key: &str,
ttl: Duration,
compute: F,
) -> CacheResult<T>
pub async fn remember<T, F, Fut>( &self, key: &str, ttl: Duration, compute: F, ) -> CacheResult<T>
Remember pattern: get from cache or compute and store
Sourcepub async fn remember_default<T, F, Fut>(
&self,
key: &str,
compute: F,
) -> CacheResult<T>
pub async fn remember_default<T, F, Fut>( &self, key: &str, compute: F, ) -> CacheResult<T>
Remember pattern with default TTL
Sourcepub async fn stats(&self) -> CacheResult<CacheStats>
pub async fn stats(&self) -> CacheResult<CacheStats>
Get cache statistics
Auto Trait Implementations§
impl<B> Freeze for Cache<B>where
B: Freeze,
impl<B> RefUnwindSafe for Cache<B>where
B: RefUnwindSafe,
impl<B> Send for Cache<B>
impl<B> Sync for Cache<B>
impl<B> Unpin for Cache<B>where
B: Unpin,
impl<B> UnwindSafe for Cache<B>where
B: UnwindSafe,
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