CacheManager

Struct CacheManager 

Source
pub struct CacheManager<B, S = JsonSerializer, M = NoopMetrics>{ /* private fields */ }
Expand description

High-level cache manager with pluggable serialization and metrics

Generic over:

  • B: The cache backend (Memory, Redis, MultiTier)
  • S: The serializer (JSON, MessagePack, Bincode)
  • M: The metrics collector

Implementations§

Source§

impl<B: CacheBackend + DependencyBackend> CacheManager<B, JsonSerializer, NoopMetrics>

Source

pub fn new(backend: B) -> Self

Create a new CacheManager with default JSON serializer and no metrics

Source

pub fn with_config(backend: B, config: CacheManagerConfig) -> Self

Create with custom config

Source§

impl<B, S, M> CacheManager<B, S, M>

Source

pub fn with_serializer_and_metrics( backend: B, serializer: S, metrics: M, config: CacheManagerConfig, ) -> Self

Create a CacheManager with custom serializer and metrics

Source

pub fn group(&self, namespace: impl Into<String>) -> CacheGroup<'_, B, S, M>

Create a namespaced cache group

Source

pub async fn get<T>(&self, key: impl CacheKey) -> Result<CacheResult<T>>

Get a value from cache

Source

pub async fn set<T>( &self, key: impl CacheKey, value: T, options: impl Into<CacheOptions>, ) -> Result<()>
where T: Serialize,

Set a value in cache

Source

pub async fn get_or_compute<T, F, Fut>( &self, key: impl CacheKey, computer: F, options: Option<CacheOptions>, ) -> Result<CacheResult<T>>
where T: Serialize + DeserializeOwned + Send + 'static, F: FnOnce() -> Fut + Send + 'static, Fut: Future<Output = Result<T>> + Send + 'static,

Get a value from cache, or compute it if missing (coalesced)

Source

pub async fn delete(&self, key: impl CacheKey) -> Result<bool>

Delete a key from cache (with cascade invalidation)

Source

pub async fn invalidate(&self, key: impl CacheKey) -> Result<u64>

Invalidate a key and all its dependents (cascade invalidation)

Returns the number of entries invalidated

Source

pub async fn exists(&self, key: impl CacheKey) -> Result<bool>

Check if key exists in cache

Source

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

Clear all entries from cache

Source

pub async fn stats(&self) -> Result<CacheStats>

Get cache statistics

Source

pub async fn len(&self) -> Result<usize>

Get the number of entries

Source

pub async fn is_empty(&self) -> Result<bool>

Check if cache is empty

Source§

impl<B, S, M> CacheManager<B, S, M>

Source

pub async fn delete_by_tag(&self, tag: &str) -> Result<u64>

Delete all entries with a specific tag

Source

pub async fn get_keys_by_tag(&self, tag: &str) -> Result<Vec<String>>

Get all keys by tag

Trait Implementations§

Source§

impl<B, S, M> CacheManagerReadThroughExt<B, S, M> for CacheManager<B, S, M>

Source§

fn read_through<K, V, L>( self, loader: L, options: CacheOptions, ) -> ReadThroughCache<B, S, M, K, V, L>
where L: Loader<K, V>, K: CacheKey + Clone + Send + Sync + 'static, V: Serialize + DeserializeOwned + Send + Sync + Clone + 'static,

Source§

impl<B, S, M> Clone for CacheManager<B, S, M>

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<B, S, M> Freeze for CacheManager<B, S, M>

§

impl<B, S = JsonSerializer, M = NoopMetrics> !RefUnwindSafe for CacheManager<B, S, M>

§

impl<B, S, M> Send for CacheManager<B, S, M>

§

impl<B, S, M> Sync for CacheManager<B, S, M>

§

impl<B, S, M> Unpin for CacheManager<B, S, M>

§

impl<B, S = JsonSerializer, M = NoopMetrics> !UnwindSafe for CacheManager<B, S, M>

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