pub struct TwoLevelStore<T> { /* private fields */ }Expand description
Two-level cache implementation combining in-memory LRU cache and Redis
§Type Parameters
T- The type of data being cached
Implementations§
Source§impl<T: Clone + Serialize + DeserializeOwned> TwoLevelStore<T>
impl<T: Clone + Serialize + DeserializeOwned> TwoLevelStore<T>
Sourcepub fn new(cache: RedisCache, size: NonZeroUsize, ttl: Duration) -> Self
pub fn new(cache: RedisCache, size: NonZeroUsize, ttl: Duration) -> Self
Sourcepub async fn set(&self, key: &str, value: T) -> Result<(), Error>
pub async fn set(&self, key: &str, value: T) -> Result<(), Error>
Stores a value in both cache levels
§Arguments
key- The key under which to store the valuevalue- The value to store
§Returns
Ok(())- Successfully stored in both cachesErr(Error)- Failed to store in Redis
§Notes
- Calculates TTL aligned with interval boundaries
- Stores in Redis first, then LRU cache
Sourcepub async fn get(&self, key: &str) -> Result<Option<T>, Error>
pub async fn get(&self, key: &str) -> Result<Option<T>, Error>
Retrieves a value from the cache
§Arguments
key- The key to look up
§Returns
Ok(Some(T))- Value found in either cache levelOk(None)- Value not found in either cacheErr(Error)- Redis operation failed
§Notes
- Checks LRU cache first
- If not in LRU, checks Redis and updates LRU if found
- Only updates LRU if Redis TTL is within expected range
Auto Trait Implementations§
impl<T> !Freeze for TwoLevelStore<T>
impl<T> !RefUnwindSafe for TwoLevelStore<T>
impl<T> Send for TwoLevelStore<T>where
T: Send,
impl<T> Sync for TwoLevelStore<T>
impl<T> Unpin for TwoLevelStore<T>
impl<T> !UnwindSafe for TwoLevelStore<T>
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