Struct ClockProCache

Source
pub struct ClockProCache<K, V> { /* private fields */ }
Expand description

A CLOCK-Pro cache that maps keys to values.

Implementations§

Source§

impl<K, V> ClockProCache<K, V>
where K: Eq + Hash + Clone,

Source

pub fn new(capacity: usize) -> Result<Self, &'static str>

Create a new cache with the given capacity.

Source

pub fn new_with_test_capacity( capacity: usize, test_capacity: usize, ) -> Result<Self, &'static str>

Create a new cache with the given value and test capacities.

The test capacity is used for tracking recently evicted entries, so that they will be considered frequently used if they get reinserted.

Source

pub fn len(&self) -> usize

Returns the number of cached values.

Source

pub fn is_empty(&self) -> bool

Returns true when no values are currently cached.

Source

pub fn recent_len(&self) -> usize

Returns the number of recently inserted values.

Source

pub fn frequent_len(&self) -> usize

Returns the number of frequently fetched or updated values.

Source

pub fn test_len(&self) -> usize

Returns the number of test entries.

Source

pub fn inserted(&self) -> u64

Returns how many values have been inserted into the cache overall.

Source

pub fn evicted(&self) -> u64

Returns how many values have been evicted from the cache.

Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Get a mutable reference to the value in the cache mapped to by key.

If no value exists for key, this returns None.

Source

pub fn get<Q>(&mut self, key: &Q) -> Option<&V>
where Q: Hash + Eq + ?Sized, K: Borrow<Q>,

Get an immutable reference to the value in the cache mapped to by key.

If no value exists for key, this returns None.

Source

pub fn contains_key<Q>(&mut self, key: &Q) -> bool
where Q: Hash + Eq + ?Sized, K: Borrow<Q>,

Returns true if there is a value in the cache mapped to by key.

Source

pub fn insert(&mut self, key: K, value: V) -> bool

Map key to value in the cache, possibly evicting old entries.

This method returns true when this is a new entry, and false if an existing entry was updated.

Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Remove the cache entry mapped to by key.

This method returns the value removed from the cache. If key did not map to any value, then this returns None.

Trait Implementations§

Source§

impl<K, V> Send for ClockProCache<K, V>
where K: Send, V: Send,

Source§

impl<K, V> Sync for ClockProCache<K, V>
where K: Sync, V: Sync,

Auto Trait Implementations§

§

impl<K, V> Freeze for ClockProCache<K, V>

§

impl<K, V> RefUnwindSafe for ClockProCache<K, V>

§

impl<K, V> Unpin for ClockProCache<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for ClockProCache<K, V>
where K: UnwindSafe, V: 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, 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.