CacheManager

Struct CacheManager 

Source
pub struct CacheManager<B: CacheBackend> { /* private fields */ }
Expand description

The main cache manager that coordinates caching operations.

This is the primary entry point for the caching system. It wraps any CacheBackend implementation and provides a unified API.

Implementations§

Source§

impl<B: CacheBackend> CacheManager<B>

Source

pub fn new(backend: B) -> Self

Create a new cache manager with the given backend.

Source

pub fn with_options(backend: B, options: CacheOptions) -> Self

Create with custom default options.

Source

pub fn backend(&self) -> &B

Get the cache backend.

Source

pub fn metrics(&self) -> &CacheMetrics

Get the metrics collector.

Source

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

Get a value from the cache.

Source

pub async fn set<T>( &self, key: &CacheKey, value: &T, options: Option<&CacheOptions>, ) -> CacheResult<()>
where T: Serialize + Sync,

Set a value in the cache.

Source

pub async fn get_or_set<T, F, Fut>( &self, key: &CacheKey, f: F, options: Option<&CacheOptions>, ) -> CacheResult<T>
where T: Serialize + DeserializeOwned + Sync, F: FnOnce() -> Fut, Fut: Future<Output = CacheResult<T>>,

Get or compute a value.

If the value exists in cache, returns it. Otherwise, calls the provided function to compute the value, caches it, and returns it.

Source

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

Delete a value from the cache.

Source

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

Check if a key exists in the cache.

Source

pub async fn invalidate_pattern(&self, pattern: &KeyPattern) -> CacheResult<u64>

Invalidate cache entries by pattern.

Source

pub async fn invalidate_entity(&self, entity: &str) -> CacheResult<u64>

Invalidate all entries for an entity type.

Source

pub async fn invalidate_record<I: Display>( &self, entity: &str, id: I, ) -> CacheResult<u64>

Invalidate a specific record.

Source

pub async fn invalidate_tags(&self, tags: &[EntityTag]) -> CacheResult<u64>

Invalidate entries by tags.

Source

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

Clear all entries from the cache.

Source

pub fn stats(&self) -> CacheStats

Get cache statistics.

Trait Implementations§

Source§

impl<B: Clone + CacheBackend> Clone for CacheManager<B>

Source§

fn clone(&self) -> CacheManager<B>

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

§

impl<B> RefUnwindSafe for CacheManager<B>
where B: RefUnwindSafe,

§

impl<B> Send for CacheManager<B>

§

impl<B> Sync for CacheManager<B>

§

impl<B> Unpin for CacheManager<B>

§

impl<B> UnwindSafe for CacheManager<B>
where B: RefUnwindSafe,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more