pub struct DistributedCache { /* private fields */ }Expand description
Distributed cache for contexts
Implementations§
Source§impl DistributedCache
impl DistributedCache
Sourcepub fn new(store: Arc<dyn ContextStore>) -> Self
pub fn new(store: Arc<dyn ContextStore>) -> Self
Create a new distributed cache
Sourcepub fn with_config(
store: Arc<dyn ContextStore>,
strategy: CacheStrategy,
default_ttl: Option<Duration>,
) -> Self
pub fn with_config( store: Arc<dyn ContextStore>, strategy: CacheStrategy, default_ttl: Option<Duration>, ) -> Self
Create with custom strategy and TTL
Sourcepub async fn get(&self, session_id: &str) -> Result<Option<DistributedContext>>
pub async fn get(&self, session_id: &str) -> Result<Option<DistributedContext>>
Get a context from cache
Sourcepub async fn put(&self, context: &DistributedContext) -> Result<()>
pub async fn put(&self, context: &DistributedContext) -> Result<()>
Put a context into cache
Sourcepub async fn put_with_ttl(
&self,
context: &DistributedContext,
ttl: Option<Duration>,
) -> Result<()>
pub async fn put_with_ttl( &self, context: &DistributedContext, ttl: Option<Duration>, ) -> Result<()>
Put a context with custom TTL
Sourcepub async fn invalidate(&self, session_id: &str) -> Result<()>
pub async fn invalidate(&self, session_id: &str) -> Result<()>
Invalidate (delete) a context
Sourcepub async fn get_many(
&self,
session_ids: &[String],
) -> Result<Vec<Option<DistributedContext>>>
pub async fn get_many( &self, session_ids: &[String], ) -> Result<Vec<Option<DistributedContext>>>
Batch get multiple contexts
Sourcepub async fn put_many(&self, contexts: &[DistributedContext]) -> Result<()>
pub async fn put_many(&self, contexts: &[DistributedContext]) -> Result<()>
Batch put multiple contexts
Sourcepub async fn stats(&self) -> CacheStats
pub async fn stats(&self) -> CacheStats
Get cache statistics
Auto Trait Implementations§
impl Freeze for DistributedCache
impl !RefUnwindSafe for DistributedCache
impl Send for DistributedCache
impl Sync for DistributedCache
impl Unpin for DistributedCache
impl !UnwindSafe for DistributedCache
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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