pub struct Cache { /* private fields */ }Expand description
Cloneable application-facing cache API.
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn new(store: impl Store, prefix: impl Into<String>) -> Self
pub fn new(store: impl Store, prefix: impl Into<String>) -> Self
Wrap a cache driver and apply prefix to item and lock names.
Sourcepub async fn get<T: DeserializeOwned>(
&self,
key: &str,
) -> Result<Option<T>, Error>
pub async fn get<T: DeserializeOwned>( &self, key: &str, ) -> Result<Option<T>, Error>
Retrieve and decode a value, returning None when the key is absent.
Sourcepub async fn get_many<T: DeserializeOwned>(
&self,
keys: &[&str],
) -> Result<Vec<Option<T>>, Error>
pub async fn get_many<T: DeserializeOwned>( &self, keys: &[&str], ) -> Result<Vec<Option<T>>, Error>
Retrieve several values in input order.
Sourcepub async fn put<T: Serialize>(
&self,
key: &str,
value: &T,
seconds: i64,
) -> Result<(), Error>
pub async fn put<T: Serialize>( &self, key: &str, value: &T, seconds: i64, ) -> Result<(), Error>
Store a value for a signed number of seconds.
A zero or negative lifetime removes the key instead.
Sourcepub async fn put_many<T: Serialize>(
&self,
values: &[(String, T)],
seconds: i64,
) -> Result<(), Error>
pub async fn put_many<T: Serialize>( &self, values: &[(String, T)], seconds: i64, ) -> Result<(), Error>
Store several values with one lifetime.
Sourcepub async fn forever<T: Serialize>(
&self,
key: &str,
value: &T,
) -> Result<(), Error>
pub async fn forever<T: Serialize>( &self, key: &str, value: &T, ) -> Result<(), Error>
Store a value without expiration.
Sourcepub async fn add<T: Serialize>(
&self,
key: &str,
value: &T,
seconds: Option<i64>,
) -> Result<bool, Error>
pub async fn add<T: Serialize>( &self, key: &str, value: &T, seconds: Option<i64>, ) -> Result<bool, Error>
Store a value only when the key is absent.
None stores indefinitely. A zero or negative lifetime performs no write.
Sourcepub async fn pull<T: DeserializeOwned>(
&self,
key: &str,
) -> Result<Option<T>, Error>
pub async fn pull<T: DeserializeOwned>( &self, key: &str, ) -> Result<Option<T>, Error>
Return and remove a value atomically.
Sourcepub async fn missing(&self, key: &str) -> Result<bool, Error>
pub async fn missing(&self, key: &str) -> Result<bool, Error>
Determine whether a key does not exist.
Sourcepub async fn increment(&self, key: &str, amount: i64) -> Result<i64, Error>
pub async fn increment(&self, key: &str, amount: i64) -> Result<i64, Error>
Atomically increment an integer, creating an indefinite value when absent.
Sourcepub async fn decrement(&self, key: &str, amount: i64) -> Result<i64, Error>
pub async fn decrement(&self, key: &str, amount: i64) -> Result<i64, Error>
Atomically decrement an integer, creating an indefinite value when absent.
Sourcepub async fn touch(&self, key: &str, seconds: i64) -> Result<bool, Error>
pub async fn touch(&self, key: &str, seconds: i64) -> Result<bool, Error>
Replace an existing key’s lifetime, or remove it for a non-positive lifetime.
Sourcepub async fn forget(&self, key: &str) -> Result<bool, Error>
pub async fn forget(&self, key: &str) -> Result<bool, Error>
Remove one item, returning whether it existed.
Sourcepub async fn flush(&self) -> Result<(), Error>
pub async fn flush(&self) -> Result<(), Error>
Remove all entries from the selected backend, ignoring this handle’s prefix.
Sourcepub async fn remember<T, F, Fut, E>(
&self,
key: &str,
seconds: i64,
resolve: F,
) -> Result<T, RememberError<E>>
pub async fn remember<T, F, Fut, E>( &self, key: &str, seconds: i64, resolve: F, ) -> Result<T, RememberError<E>>
Retrieve a value or resolve and cache it for the given lifetime.
Sourcepub async fn remember_forever<T, F, Fut, E>(
&self,
key: &str,
resolve: F,
) -> Result<T, RememberError<E>>
pub async fn remember_forever<T, F, Fut, E>( &self, key: &str, resolve: F, ) -> Result<T, RememberError<E>>
Retrieve a value or resolve and cache it without expiration.
Sourcepub fn lock(&self, name: &str, seconds: i64) -> Lock
pub fn lock(&self, name: &str, seconds: i64) -> Lock
Create a lock with a random owner token. Non-positive seconds means no expiration.
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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> ⓘ
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> ⓘ
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