pub struct L2Cache { /* private fields */ }Expand description
L2 Cache using Redis with ConnectionManager for automatic reconnection
Implementations§
Source§impl L2Cache
impl L2Cache
Sourcepub async fn new() -> Result<Self>
pub async fn new() -> Result<Self>
Create new L2 cache with ConnectionManager for automatic reconnection
Sourcepub async fn get(&self, key: &str) -> Option<Value>
pub async fn get(&self, key: &str) -> Option<Value>
Get value from L2 cache using persistent ConnectionManager
Sourcepub async fn get_with_ttl(&self, key: &str) -> Option<(Value, Option<Duration>)>
pub async fn get_with_ttl(&self, key: &str) -> Option<(Value, Option<Duration>)>
Get value with its remaining TTL from L2 cache
Returns tuple of (value, ttl_seconds) if key exists TTL is in seconds, None if key doesn’t exist or has no expiration
Sourcepub async fn set_with_ttl(
&self,
key: &str,
value: Value,
ttl: Duration,
) -> Result<()>
pub async fn set_with_ttl( &self, key: &str, value: Value, ttl: Duration, ) -> Result<()>
Set value with custom TTL using persistent ConnectionManager
Sourcepub async fn remove(&self, key: &str) -> Result<()>
pub async fn remove(&self, key: &str) -> Result<()>
Remove value from cache using persistent ConnectionManager
Sourcepub async fn scan_keys(&self, pattern: &str) -> Result<Vec<String>>
pub async fn scan_keys(&self, pattern: &str) -> Result<Vec<String>>
Scan keys matching a pattern (glob-style: *, ?, [])
Uses Redis SCAN command (non-blocking, cursor-based iteration) This is safe for production use, unlike KEYS command.
§Arguments
pattern- Glob-style pattern (e.g., “user:”, “product:123:”)
§Returns
Vector of matching key names
§Examples
// Find all user cache keys
let keys = cache.scan_keys("user:*").await?;
// Find specific user's cache keys
let keys = cache.scan_keys("user:123:*").await?;Sourcepub async fn remove_bulk(&self, keys: &[String]) -> Result<usize>
pub async fn remove_bulk(&self, keys: &[String]) -> Result<usize>
Remove multiple keys at once (bulk delete)
More efficient than calling remove() multiple times
Sourcepub async fn health_check(&self) -> bool
pub async fn health_check(&self) -> bool
Health check
Trait Implementations§
Source§impl CacheBackend for L2Cache
Implement CacheBackend trait for L2Cache
impl CacheBackend for L2Cache
Implement CacheBackend trait for L2Cache
This allows L2Cache to be used as a pluggable backend in the multi-tier cache system.
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Option<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Option<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn set_with_ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: Value,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn set_with_ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: Value,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn remove<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remove<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl L2CacheBackend for L2Cache
Implement L2CacheBackend trait for L2Cache
impl L2CacheBackend for L2Cache
Implement L2CacheBackend trait for L2Cache
This extends CacheBackend with TTL introspection capabilities needed for L2->L1 promotion.