mlcr

Struct Cache

Source
pub struct Cache { /* private fields */ }
Expand description

A learning cache tracker.

This keeps track of cache blocks.

A cache block represents some data, which is not managed by the cache tracker. The cache block is said to be touched when this data is used in some way.

The ideal replacement is the block which is used in the most distant future. As this is not possible to know in advance, we make a prediction or a approximate ideal replacement, which is based around various data points of the block such as the time of the last uses, or the number of touches.

The aim of the cache tracker is to provided approximate ideal replacements. Numerous algorithms for making these predictions exists (examples are LRU, PLRU, LFU, MFU, MRU, ARC, etc.), but MLCR uses an approach which is radically different: It feeds the data points into a neural network and lets this estimate the tick of the next touch.

Implementations§

Source§

impl Cache

Source

pub fn new() -> Cache

Create a new cache tracker.

Source

pub fn touch(&mut self, id: Id)

Touch a cache block.

This should be called whenever the object id represents is used (read, written, etc.).

This will train the neural network with the new data.

Source

pub fn insert(&mut self, id: Id)

Insert a new cache block into the cache tracker.

Source

pub fn remove(&mut self, id: Id)

Remove a cache block.

Source

pub fn cold(&mut self) -> ColdIter

Get an iterator over blocks from cold to hot.

Source

pub fn trim(&mut self, to: usize) -> Take<ColdIter>

Get at iterator over blocks to remove to trim the cache tracker to to.

Note that this won’t remove the blocks, and this should be handled manually with the remove method.

Auto Trait Implementations§

§

impl Freeze for Cache

§

impl RefUnwindSafe for Cache

§

impl Send for Cache

§

impl Sync for Cache

§

impl Unpin for Cache

§

impl UnwindSafe for Cache

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> Erased for T