pub struct Resident<R, K> { /* private fields */ }Expand description
Entries in the order they were placed, each owned by one run and named by its address on disk.
A hit does not reorder: the model trims first in, first out, and only placing an address again moves it to the newest end.
Implementations§
Source§impl<R: Ord + Clone, K: Ord + Clone> Resident<R, K>
impl<R: Ord + Clone, K: Ord + Clone> Resident<R, K>
Sourcepub fn new(budget_bytes: usize) -> Self
pub fn new(budget_bytes: usize) -> Self
An empty cache that never holds more than budget_bytes.
Sourcepub fn insert<E>(
&mut self,
owner: &R,
key: &K,
load: impl FnOnce(&K) -> Result<Vec<u8>, E>,
) -> Result<(), E>
pub fn insert<E>( &mut self, owner: &R, key: &K, load: impl FnOnce(&K) -> Result<Vec<u8>, E>, ) -> Result<(), E>
Reads key from disk through load and places it, then drops the
oldest entries until the cache is within its budget. A frozen run
is not placed; an entry larger than the budget is not kept. A
failed load changes nothing and its error is returned.
Sourcepub fn read<E>(
&mut self,
owner: &R,
key: &K,
load: impl FnOnce(&K) -> Result<Vec<u8>, E>,
) -> Result<Arc<[u8]>, E>
pub fn read<E>( &mut self, owner: &R, key: &K, load: impl FnOnce(&K) -> Result<Vec<u8>, E>, ) -> Result<Arc<[u8]>, E>
Answers the cached bytes on a hit; on a miss reads them through
load, places them as Self::insert does, and answers them.
Sourcepub fn evict_oldest(&mut self)
pub fn evict_oldest(&mut self)
Drops the oldest entry, when the system asks for memory back or a beat evicts.
Sourcepub fn freeze(&mut self, owner: &R)
pub fn freeze(&mut self, owner: &R)
Drops every entry of owner and places nothing for it afterwards.
Sourcepub fn resident_bytes(&self) -> usize
pub fn resident_bytes(&self) -> usize
The bytes the cache holds now.