TieredCache

Struct TieredCache 

Source
pub struct TieredCache<L1, L2>
where L1: CacheStore, L2: CacheStore,
{ /* private fields */ }
Expand description

Multi-tier cache with L1 (in-memory) and L2 (distributed) layers

Implementations§

Source§

impl<L1, L2> TieredCache<L1, L2>
where L1: CacheStore, L2: CacheStore,

Source

pub fn new(l1: Arc<L1>, l2: Arc<L2>) -> Self

Create new tiered cache

§Examples
use armature_cache::*;

let l1 = Arc::new(InMemoryCache::new());
let l2 = Arc::new(RedisCache::new(config).await?);
let cache = TieredCache::new(l1, l2);
Source

pub fn with_config(l1: Arc<L1>, l2: Arc<L2>, config: TieredCacheConfig) -> Self

Create with custom configuration

Source

pub async fn get(&self, key: &str) -> CacheResult<Option<String>>

Get value from cache (checks L1 then L2)

Source

pub async fn set( &self, key: &str, value: String, ttl: Option<Duration>, ) -> CacheResult<()>

Set value in cache (writes to both L1 and L2)

Source

pub async fn delete(&self, key: &str) -> CacheResult<()>

Delete from both L1 and L2

Source

pub async fn exists(&self, key: &str) -> CacheResult<bool>

Check if key exists (checks L1 then L2)

Source

pub async fn clear(&self) -> CacheResult<()>

Clear both L1 and L2

Source

pub async fn stats(&self) -> CacheStats

Get cache statistics

Trait Implementations§

Source§

impl<L1, L2> Clone for TieredCache<L1, L2>
where L1: CacheStore, L2: CacheStore,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<L1, L2> Freeze for TieredCache<L1, L2>

§

impl<L1, L2> RefUnwindSafe for TieredCache<L1, L2>

§

impl<L1, L2> Send for TieredCache<L1, L2>

§

impl<L1, L2> Sync for TieredCache<L1, L2>

§

impl<L1, L2> Unpin for TieredCache<L1, L2>

§

impl<L1, L2> UnwindSafe for TieredCache<L1, L2>

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> 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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V