pub struct LogicalCache<K, V> { /* private fields */ }Expand description
A bounded logical cache charged to a ByteBudget.
Implementations§
Source§impl<K, V> LogicalCache<K, V>
impl<K, V> LogicalCache<K, V>
Sourcepub fn new(budget: ByteBudget) -> Result<Self, ResourceError>
pub fn new(budget: ByteBudget) -> Result<Self, ResourceError>
Build a cache charged to budget. A zero-limit budget makes every
insert a no-op (the cache is effectively disabled).
§Errors
Returns ResourceError if the initial zero-byte reservation cannot be
created (only when the budget is already over its limit).
Sourcepub fn get(&mut self, key: &K) -> Option<&V>
pub fn get(&mut self, key: &K) -> Option<&V>
Look up key, marking it most-recently-used on a hit.
Sourcepub fn insert(&mut self, key: K, value: V, bytes: usize) -> bool
pub fn insert(&mut self, key: K, value: V, bytes: usize) -> bool
Insert or replace an entry whose retained size is bytes. Evicts LRU
entries until it fits; a value larger than the whole budget is not
cached. Returns whether the entry is now resident.
Sourcepub fn retain(&mut self, keep: impl FnMut(&K, &V) -> bool) -> usize
pub fn retain(&mut self, keep: impl FnMut(&K, &V) -> bool) -> usize
Drop every entry keep rejects, releasing its bytes (counted as
evictions). Returns how many entries were dropped.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Occupancy and counters.
Auto Trait Implementations§
impl<K, V> Freeze for LogicalCache<K, V>
impl<K, V> RefUnwindSafe for LogicalCache<K, V>
impl<K, V> Send for LogicalCache<K, V>
impl<K, V> Sync for LogicalCache<K, V>
impl<K, V> Unpin for LogicalCache<K, V>
impl<K, V> UnsafeUnpin for LogicalCache<K, V>
impl<K, V> UnwindSafe for LogicalCache<K, V>
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