pub struct ArcCache<K, V> { /* private fields */ }Expand description
Adaptive Replacement Cache with configurable capacity and optional per-entry TTL.
§Type parameters
K: key type – must beEq + Hash + Clone.V: value type.
Implementations§
Source§impl<K, V> ArcCache<K, V>
impl<K, V> ArcCache<K, V>
Sourcepub fn new(cap: usize) -> Self
pub fn new(cap: usize) -> Self
Create a new ArcCache with the given capacity.
Capacity must be at least 1; a capacity of 0 is treated as 1 internally.
Sourcepub fn get(&mut self, key: &K) -> Option<&V>
pub fn get(&mut self, key: &K) -> Option<&V>
Look up key and return a reference to its value, promoting as needed.
Expired entries are lazily removed and treated as misses.
Sourcepub fn put(&mut self, key: K, value: V) -> Option<V>
pub fn put(&mut self, key: K, value: V) -> Option<V>
Insert key -> value into the cache (no TTL).
Sourcepub fn put_with_ttl(&mut self, key: K, value: V, ttl: Duration) -> Option<V>
pub fn put_with_ttl(&mut self, key: K, value: V, ttl: Duration) -> Option<V>
Insert key -> value into the cache with a TTL.
Sourcepub fn peek(&self, key: &K) -> Option<&V>
pub fn peek(&self, key: &K) -> Option<&V>
Read a value without promoting it.
Checks t1 and t2 but does NOT move entries or trigger ghost adaptation.
Expired entries return None (removal happens on next mutable access).
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Return true if key is present in t1 or t2 and not expired (without promotion).
Trait Implementations§
Source§impl<K, V> Cache<K, V> for ArcCache<K, V>
impl<K, V> Cache<K, V> for ArcCache<K, V>
Source§fn get(&mut self, key: &K) -> Option<&V>
fn get(&mut self, key: &K) -> Option<&V>
Look up
key, returning a reference to the value if present. Read moreSource§fn put_with_ttl(&mut self, key: K, value: V, ttl: Duration) -> Option<V>
fn put_with_ttl(&mut self, key: K, value: V, ttl: Duration) -> Option<V>
Source§fn remove(&mut self, key: &K) -> Option<V>
fn remove(&mut self, key: &K) -> Option<V>
Remove the entry associated with
key, returning its value if present. Read moreSource§fn peek(&self, key: &K) -> Option<&V>
fn peek(&self, key: &K) -> Option<&V>
Look up
key without updating access metadata (no promotion). Read moreSource§fn contains_key(&self, key: &K) -> bool
fn contains_key(&self, key: &K) -> bool
Source§fn values(&self) -> Vec<&V>
fn values(&self) -> Vec<&V>
Return all live (non-expired) values currently stored in the cache. Read more
Auto Trait Implementations§
impl<K, V> Freeze for ArcCache<K, V>
impl<K, V> RefUnwindSafe for ArcCache<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for ArcCache<K, V>
impl<K, V> Sync for ArcCache<K, V>
impl<K, V> Unpin for ArcCache<K, V>
impl<K, V> UnsafeUnpin for ArcCache<K, V>
impl<K, V> UnwindSafe for ArcCache<K, V>where
K: RefUnwindSafe,
V: 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