pub struct Cache<K, V> { /* private fields */ }
Expand description
Application level cache which can store entries both in a locally and distributed using redis
Implementations§
Source§impl<K, V> Cache<K, V>
impl<K, V> Cache<K, V>
pub fn new(ttl: Duration) -> Self
pub fn with_redis( self, redis: ConnectionManager, prefix: impl Into<String>, ttl: Duration, hash_key: bool, ) -> Self
Sourcepub fn longest_ttl(&self) -> Duration
pub fn longest_ttl(&self) -> Duration
Return the longest duration an entry might live for
pub async fn get(&self, key: &K) -> Result<Option<V>, CacheError>
Sourcepub async fn insert(&self, key: K, value: V) -> Result<(), CacheError>
pub async fn insert(&self, key: K, value: V) -> Result<(), CacheError>
Insert a key-value pair with the cache’s default TTL
Sourcepub async fn insert_with_ttl(
&self,
key: K,
value: V,
ttl: Duration,
) -> Result<(), CacheError>
pub async fn insert_with_ttl( &self, key: K, value: V, ttl: Duration, ) -> Result<(), CacheError>
Insert an entry with a custom TTL
Note that TTLs larger than the configured one will be ignored
Auto Trait Implementations§
impl<K, V> Freeze for Cache<K, V>
impl<K, V> !RefUnwindSafe for Cache<K, V>
impl<K, V> Send for Cache<K, V>
impl<K, V> Sync for Cache<K, V>
impl<K, V> Unpin for Cache<K, V>
impl<K, V> !UnwindSafe for Cache<K, V>
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> 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