pub struct TtlLruStore<T> { /* private fields */ }Expand description
A thread-safe storage component combining TTL (Time-To-Live) and LRU (Least Recently Used) caching strategies
§Type Parameters
T- The type of values to store, must implement Expired trait
Implementations§
Source§impl<T: Expired + Clone> TtlLruStore<T>
impl<T: Expired + Clone> TtlLruStore<T>
Sourcepub fn new(size: NonZeroUsize) -> Self
pub fn new(size: NonZeroUsize) -> Self
Sourcepub async fn get(&self, key: &str) -> Option<T>
pub async fn get(&self, key: &str) -> Option<T>
Retrieves a value from the cache if it exists and hasn’t expired
§Arguments
key- The key to look up
§Returns
Some(T)- The value if found and not expiredNone- If key doesn’t exist or value has expired
§Notes
- Uses peek() instead of get() to avoid updating LRU order
- Returns a clone of the value to maintain thread safety
Sourcepub async fn purge_expired(&self)
pub async fn purge_expired(&self)
This method should be called periodically to free up memory from expired “garbage” data.
Auto Trait Implementations§
impl<T> !Freeze for TtlLruStore<T>
impl<T> !RefUnwindSafe for TtlLruStore<T>
impl<T> Send for TtlLruStore<T>where
T: Send,
impl<T> Sync for TtlLruStore<T>
impl<T> Unpin for TtlLruStore<T>
impl<T> UnwindSafe for TtlLruStore<T>where
T: RefUnwindSafe,
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