Skip to main content

Cache

Struct Cache 

Source
pub struct Cache;

Implementations§

Source§

impl Cache

Source

pub async fn get<T: DeserializeOwned>( key: &str, ) -> Result<Option<T>, CacheError>

Retrieve a cached value. Returns None on miss or expiry.

Source

pub async fn set<T: Serialize>( key: &str, value: &T, ttl: Option<Duration>, ) -> Result<(), CacheError>

Store a value. ttl = None means no expiry.

Source

pub async fn forget(key: &str) -> Result<(), CacheError>

Remove a key.

Source

pub async fn flush() -> Result<(), CacheError>

Remove all keys (scoped to the current database / memory store).

Source

pub async fn remember<T, F, Fut, E>( key: &str, ttl: Duration, f: F, ) -> Result<T, CacheError>
where T: Serialize + DeserializeOwned + Send, F: FnOnce() -> Fut, Fut: Future<Output = Result<T, E>>, E: Display,

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.