pub struct CacheManager { /* private fields */ }Expand description
Manager for multiple cache stores.
Implementations§
Source§impl CacheManager
impl CacheManager
pub fn new(default: &str) -> Self
pub fn register<S: CacheStore + 'static>(&mut self, name: &str, store: S)
pub fn store(&self, name: &str) -> Result<Arc<dyn CacheStore>, CacheError>
pub fn default_store(&self) -> Result<Arc<dyn CacheStore>, CacheError>
pub fn set_default(&mut self, name: &str)
pub fn default_name(&self) -> &str
pub fn store_names(&self) -> Vec<String>
Sourcepub fn lock(&self, key: &str, ttl: Duration) -> Result<Lock, CacheError>
pub fn lock(&self, key: &str, ttl: Duration) -> Result<Lock, CacheError>
Create a Lock on the default store. The store must support locks
(array or redis); returns CacheError::Store otherwise.
Mirrors Laravel’s Cache::lock('key', $seconds).
Sourcepub fn store_lock(
&self,
name: &str,
key: &str,
ttl: Duration,
) -> Result<Lock, CacheError>
pub fn store_lock( &self, name: &str, key: &str, ttl: Duration, ) -> Result<Lock, CacheError>
Create a Lock on a named store.
Sourcepub async fn with_lock<F, Fut, T>(
&self,
key: &str,
ttl: Duration,
wait: Duration,
callback: F,
) -> Result<T, CacheError>
pub async fn with_lock<F, Fut, T>( &self, key: &str, ttl: Duration, wait: Duration, callback: F, ) -> Result<T, CacheError>
Acquire a lock (blocking up to wait), run callback while holding
it, then release. Mirrors Laravel’s Cache::withLock($key, $callback, $seconds).
Sourcepub async fn get_locked<F, Fut>(
&self,
key: &str,
ttl: Duration,
callback: F,
) -> Result<String, CacheError>
pub async fn get_locked<F, Fut>( &self, key: &str, ttl: Duration, callback: F, ) -> Result<String, CacheError>
When the lock is free, run callback while holding it; when another
process holds the lock, return the previously cached value instead.
The callback is responsible for storing its own result via the cache
(Laravel’s Cache::getLocked($key, $callback, $seconds)).
Sourcepub async fn get(&self, key: &str) -> Result<Option<String>, CacheError>
pub async fn get(&self, key: &str) -> Result<Option<String>, CacheError>
Convenience: get from the default store.
Sourcepub async fn set(
&self,
key: &str,
value: &str,
ttl_seconds: Option<u64>,
) -> Result<(), CacheError>
pub async fn set( &self, key: &str, value: &str, ttl_seconds: Option<u64>, ) -> Result<(), CacheError>
Convenience: set on the default store.
Sourcepub async fn forever(&self, key: &str, value: &str) -> Result<(), CacheError>
pub async fn forever(&self, key: &str, value: &str) -> Result<(), CacheError>
Convenience: forever on the default store.
Sourcepub async fn delete(&self, key: &str) -> Result<bool, CacheError>
pub async fn delete(&self, key: &str) -> Result<bool, CacheError>
Convenience: delete from the default store.
Sourcepub async fn has(&self, key: &str) -> Result<bool, CacheError>
pub async fn has(&self, key: &str) -> Result<bool, CacheError>
Convenience: has on the default store.
Sourcepub async fn clear(&self) -> Result<(), CacheError>
pub async fn clear(&self) -> Result<(), CacheError>
Convenience: clear the default store.
Sourcepub async fn pull(&self, key: &str) -> Result<Option<String>, CacheError>
pub async fn pull(&self, key: &str) -> Result<Option<String>, CacheError>
Convenience: pull from the default store.
Sourcepub async fn increment(&self, key: &str, by: i64) -> Result<i64, CacheError>
pub async fn increment(&self, key: &str, by: i64) -> Result<i64, CacheError>
Convenience: increment on the default store.
Trait Implementations§
Source§impl Clone for CacheManager
impl Clone for CacheManager
Auto Trait Implementations§
impl !RefUnwindSafe for CacheManager
impl !UnwindSafe for CacheManager
impl Freeze for CacheManager
impl Send for CacheManager
impl Sync for CacheManager
impl Unpin for CacheManager
impl UnsafeUnpin for CacheManager
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<T> Event for T
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