pub struct MemoryCache<T> { /* private fields */ }Expand description
Byte-bounded LRU of inflated entries plus any per-entry state the host
wants to keep alongside (T).
Implementations§
Source§impl<T> MemoryCache<T>
impl<T> MemoryCache<T>
pub fn new(cap_bytes: usize) -> Self
pub fn get(&mut self, key: &ApkKey, entry_name: &str) -> Option<Arc<T>>
pub fn insert( &mut self, key: &ApkKey, entry_name: &str, value: Arc<T>, size: usize, )
Sourcepub fn resize(
&mut self,
key: &ApkKey,
entry_name: &str,
value: &Arc<T>,
size: usize,
)
pub fn resize( &mut self, key: &ApkKey, entry_name: &str, value: &Arc<T>, size: usize, )
Re-charge value (still the entry cached under entry_name) at
size bytes, e.g. once per-entry state built after insertion has
grown it, and evict least recently used entries if that exceeds the
capacity. Does nothing when the slot holds something else by now.
Sourcepub fn replace(
&mut self,
key: &ApkKey,
entry_name: &str,
current: &Arc<T>,
new: Arc<T>,
) -> bool
pub fn replace( &mut self, key: &ApkKey, entry_name: &str, current: &Arc<T>, new: Arc<T>, ) -> bool
Swap the entry cached under entry_name for new when it is still
current, keeping its size and recency. Returns whether it swapped.
Sourcepub fn charged_bytes(&self, key: &ApkKey, entry_name: &str) -> Option<usize>
pub fn charged_bytes(&self, key: &ApkKey, entry_name: &str) -> Option<usize>
Size the entry cached under entry_name is charged at.
pub fn used_bytes(&self) -> usize
pub fn capacity_bytes(&self) -> usize
Sourcepub fn reserved_bytes(&self) -> usize
pub fn reserved_bytes(&self) -> usize
Bytes counted against the capacity besides the entries
(MemoryCache::set_reserved).
Sourcepub fn set_reserved(&mut self, bytes: usize)
pub fn set_reserved(&mut self, bytes: usize)
Count bytes the host holds elsewhere against the capacity, evicting
least recently used entries to make room.
Sourcepub fn set_capacity(&mut self, cap_bytes: usize)
pub fn set_capacity(&mut self, cap_bytes: usize)
Change the capacity, evicting least recently used entries if the cache now holds more.
Sourcepub fn peek(&self, key: &ApkKey, entry_name: &str) -> Option<Arc<T>>
pub fn peek(&self, key: &ApkKey, entry_name: &str) -> Option<Arc<T>>
The entry cached under entry_name, without touching its recency.
Sourcepub fn values(&self) -> impl Iterator<Item = &Arc<T>>
pub fn values(&self) -> impl Iterator<Item = &Arc<T>>
Every cached value, in no particular order (recency is not touched).
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn remove_apk(&mut self, key: &ApkKey) -> usize
pub fn remove_apk(&mut self, key: &ApkKey) -> usize
Drop every entry cached for key and return the bytes released.