Skip to main content

CacheStore

Struct CacheStore 

Source
pub struct CacheStore { /* private fields */ }
Expand description

The application’s handle on the cache.

Holds an Arc<dyn Cache> so the driver is a boot-time decision, and is itself a Cache, so a handler can call cache.remember(...) on it directly without unwrapping anything.

Implementations§

Source§

impl CacheStore

Source

pub fn from_config(config: &Config) -> Result<Self>

Build the driver named in the application configuration.

Deliberately synchronous and non-connecting: an application must boot even when Redis is momentarily down. Call CacheStore::verify when failing fast is what you want instead.

Source

pub fn build(settings: &CacheConfig) -> Result<Self>

Source

pub fn from_driver(store: impl Cache) -> Self

Wrap a driver that was built by hand.

Source

pub fn driver_handle(&self) -> Arc<dyn Cache>

The underlying driver, for a caller that needs Arc<dyn Cache>.

Source

pub async fn verify(&self) -> Result<()>

Prove the store actually works, for a doctor command or a boot check.

Trait Implementations§

Source§

impl Cache for CacheStore

Delegation, so CacheStore is usable everywhere a Cache is — including picking up every default method and all of CacheExt.

Source§

fn driver(&self) -> &'static str

The driver’s name, used in cache.hit / cache.miss events and in error messages. Telescope shows it as the store column.
Source§

fn get<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Json>>>

Fetch a value, or None when it is missing or expired. Read more
Source§

fn put<'a>( &'a self, key: &'a str, value: Json, ttl: Duration, ) -> BoxFuture<'a, Result<()>>

Store a value that expires after ttl. Read more
Source§

fn forever<'a>(&'a self, key: &'a str, value: Json) -> BoxFuture<'a, Result<()>>

Store a value with no expiry. It still goes away on Cache::flush.
Source§

fn forget<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<bool>>

Remove a key. Returns whether something was actually there.
Source§

fn flush(&self) -> BoxFuture<'_, Result<()>>

Remove everything this store owns.
Source§

fn has<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<bool>>

Whether a live (unexpired) value exists.
Source§

fn increment<'a>(&'a self, key: &'a str, by: i64) -> BoxFuture<'a, Result<i64>>

Add by to a counter, creating it at zero first. Returns the new value. Read more
Source§

fn decrement<'a>(&'a self, key: &'a str, by: i64) -> BoxFuture<'a, Result<i64>>

Subtract by from a counter. Returns the new value.
Source§

fn increment_within<'a>( &'a self, key: &'a str, by: i64, ttl: Duration, ) -> BoxFuture<'a, Result<i64>>

Increment a counter, giving it ttl only when this call created it. Read more
Source§

fn ttl<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Duration>>>

How long until a key expires: None when it is missing or immortal. Read more
Source§

fn pull<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Json>>>

Read a value and remove it in one call — Laravel’s Cache::pull.
Source§

impl Clone for CacheStore

Source§

fn clone(&self) -> CacheStore

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CacheExt for T
where T: Cache + ?Sized,

Source§

fn remember<'a, F, Fut>( &'a self, key: &'a str, ttl: Duration, compute: F, ) -> impl Future<Output = Result<Json>> + Send + 'a
where F: FnOnce() -> Fut + Send + 'a, Fut: Future<Output = Result<Json>> + Send + 'a,

Return the cached value, or compute it, store it for ttl, and return it. Read more
Source§

fn remember_forever<'a, F, Fut>( &'a self, key: &'a str, compute: F, ) -> impl Future<Output = Result<Json>> + Send + 'a
where F: FnOnce() -> Fut + Send + 'a, Fut: Future<Output = Result<Json>> + Send + 'a,

CacheExt::remember with no expiry.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.