Skip to main content

LogicalCache

Struct LogicalCache 

Source
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>
where K: Eq + Hash + Clone,

Source

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).

Source

pub fn limit(&self) -> usize

Configured byte limit for this cache.

Source

pub fn get(&mut self, key: &K) -> Option<&V>

Look up key, marking it most-recently-used on a hit.

Source

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.

Source

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.

Source

pub fn clear(&mut self)

Drop every entry, releasing all charged bytes.

Source

pub fn stats(&self) -> CacheStats

Occupancy and counters.

Auto Trait Implementations§

§

impl<K, V> Freeze for LogicalCache<K, V>
where HashMap<K, Entry<V>>: Freeze, BTreeMap<u64, K>: Freeze,

§

impl<K, V> RefUnwindSafe for LogicalCache<K, V>
where HashMap<K, Entry<V>>: RefUnwindSafe, BTreeMap<u64, K>: RefUnwindSafe,

§

impl<K, V> Send for LogicalCache<K, V>
where HashMap<K, Entry<V>>: Send, BTreeMap<u64, K>: Send,

§

impl<K, V> Sync for LogicalCache<K, V>
where HashMap<K, Entry<V>>: Sync, BTreeMap<u64, K>: Sync,

§

impl<K, V> Unpin for LogicalCache<K, V>
where HashMap<K, Entry<V>>: Unpin, BTreeMap<u64, K>: Unpin,

§

impl<K, V> UnsafeUnpin for LogicalCache<K, V>
where HashMap<K, Entry<V>>: UnsafeUnpin, BTreeMap<u64, K>: UnsafeUnpin,

§

impl<K, V> UnwindSafe for LogicalCache<K, V>
where HashMap<K, Entry<V>>: UnwindSafe, BTreeMap<u64, K>: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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.