pub struct L2Cache { /* private fields */ }Expand description
L2 cache implementation using Redis
Implementations§
Source§impl L2Cache
impl L2Cache
Sourcepub async fn new(metrics: CacheMetrics) -> Result<Self, L2Error>
pub async fn new(metrics: CacheMetrics) -> Result<Self, L2Error>
Create a new L2 cache with default configuration
Sourcepub async fn with_config(
config: L2Config,
metrics: CacheMetrics,
) -> Result<Self, L2Error>
pub async fn with_config( config: L2Config, metrics: CacheMetrics, ) -> Result<Self, L2Error>
Create a new L2 cache with custom configuration
Sourcepub async fn set(
&self,
key: String,
value: CachedResponse,
) -> Result<(), L2Error>
pub async fn set( &self, key: String, value: CachedResponse, ) -> Result<(), L2Error>
Set a value in the cache
§Performance
Target: 1-2ms (async, non-blocking) This is designed to be called asynchronously without blocking the main request
Sourcepub async fn set_with_ttl(
&self,
key: String,
value: CachedResponse,
ttl_seconds: u64,
) -> Result<(), L2Error>
pub async fn set_with_ttl( &self, key: String, value: CachedResponse, ttl_seconds: u64, ) -> Result<(), L2Error>
Set a value in the cache with custom TTL
Sourcepub async fn health_check(&self) -> bool
pub async fn health_check(&self) -> bool
Check if Redis connection is healthy
Sourcepub async fn approximate_size(&self) -> Result<usize, L2Error>
pub async fn approximate_size(&self) -> Result<usize, L2Error>
Get the current size of the cache (approximate)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for L2Cache
impl RefUnwindSafe for L2Cache
impl Send for L2Cache
impl Sync for L2Cache
impl Unpin for L2Cache
impl UnwindSafe for L2Cache
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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