Skip to main content

Resident

Struct Resident 

Source
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>

Source

pub fn new(budget_bytes: usize) -> Self

An empty cache that never holds more than budget_bytes.

Source

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.

Source

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.

Source

pub fn evict_oldest(&mut self)

Drops the oldest entry, when the system asks for memory back or a beat evicts.

Source

pub fn freeze(&mut self, owner: &R)

Drops every entry of owner and places nothing for it afterwards.

Source

pub fn resident_bytes(&self) -> usize

The bytes the cache holds now.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.