pub struct Cache;Implementations§
Source§impl Cache
impl Cache
Sourcepub async fn get<T: DeserializeOwned>(
key: &str,
) -> Result<Option<T>, CacheError>
pub async fn get<T: DeserializeOwned>( key: &str, ) -> Result<Option<T>, CacheError>
Retrieve a cached value. Returns None on miss or expiry.
Sourcepub async fn set<T: Serialize>(
key: &str,
value: &T,
ttl: Option<Duration>,
) -> Result<(), CacheError>
pub async fn set<T: Serialize>( key: &str, value: &T, ttl: Option<Duration>, ) -> Result<(), CacheError>
Store a value. ttl = None means no expiry.
Sourcepub async fn flush() -> Result<(), CacheError>
pub async fn flush() -> Result<(), CacheError>
Remove all keys (scoped to the current database / memory store).
Sourcepub async fn remember<T, F, Fut, E>(
key: &str,
ttl: Duration,
f: F,
) -> Result<T, CacheError>
pub async fn remember<T, F, Fut, E>( key: &str, ttl: Duration, f: F, ) -> Result<T, CacheError>
Return the cached value if present; otherwise call f, store the
result for ttl, and return it.
The fallback closure may return any error type that implements
Display — it is converted to CacheError::Fetch.
Auto Trait Implementations§
impl Freeze for Cache
impl RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl UnsafeUnpin for Cache
impl UnwindSafe 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