L2Cache

Struct L2Cache 

Source
pub struct L2Cache { /* private fields */ }
Expand description

L2 Cache using Redis with ConnectionManager for automatic reconnection

Implementations§

Source§

impl L2Cache

Source

pub async fn new() -> Result<Self>

Create new L2 cache with ConnectionManager for automatic reconnection

Source

pub async fn get(&self, key: &str) -> Option<Value>

Get value from L2 cache using persistent ConnectionManager

Source

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

Source

pub async fn set_with_ttl( &self, key: &str, value: Value, ttl: Duration, ) -> Result<()>

Set value with custom TTL using persistent ConnectionManager

Source

pub async fn remove(&self, key: &str) -> Result<()>

Remove value from cache using persistent ConnectionManager

Source

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?;
Source

pub async fn remove_bulk(&self, keys: &[String]) -> Result<usize>

Remove multiple keys at once (bulk delete)

More efficient than calling remove() multiple times

Source

pub async fn health_check(&self) -> bool

Health check

Trait Implementations§

Source§

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,

Get value from cache by key Read more
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,

Set value in cache with time-to-live Read more
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,

Remove value from cache Read more
Source§

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check if cache backend is healthy Read more
Source§

fn name(&self) -> &str

Get the name of this cache backend Read more
Source§

impl L2CacheBackend for L2Cache

Implement L2CacheBackend trait for L2Cache

This extends CacheBackend with TTL introspection capabilities needed for L2->L1 promotion.

Source§

fn get_with_ttl<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Option<(Value, Option<Duration>)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get value with its remaining TTL from L2 cache Read more

Auto Trait Implementations§

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.