CacheShard

Struct CacheShard 

Source
pub struct CacheShard<Key, Val, We, B, L, Plh> {
Show 16 fields hash_builder: B, map: HashTable<NonZeroU32>, entries: LinkedSlab<Entry<Key, Val, Plh>>, cold_head: Option<NonZeroU32>, hot_head: Option<NonZeroU32>, ghost_head: Option<NonZeroU32>, weight_target_hot: u64, weight_capacity: u64, weight_hot: u64, weight_cold: u64, num_hot: usize, num_cold: usize, num_non_resident: usize, capacity_non_resident: usize, weighter: We, pub(crate) lifecycle: L,
}
Expand description

A bounded cache using a modified CLOCK-PRO eviction policy. The implementation allows some parallelism as gets don’t require exclusive access. Any evicted items are returned so they can be dropped by the caller, outside the locks.

Fields§

§hash_builder: B§map: HashTable<NonZeroU32>

Map to an entry in the entries slab. Note that the actual key/value/hash are not stored in the map but in the slab.

§entries: LinkedSlab<Entry<Key, Val, Plh>>

Slab holding entries

§cold_head: Option<NonZeroU32>

Head of cold list, containing Cold entries. Only contains entries of kind Resident.

§hot_head: Option<NonZeroU32>

Head of hot list, containing Hot entries. Only contains entries of kind Resident.

§ghost_head: Option<NonZeroU32>

Head of ghost list, containing non-resident/Hash entries. Only contains entries of kind Ghost.

§weight_target_hot: u64§weight_capacity: u64§weight_hot: u64§weight_cold: u64§num_hot: usize§num_cold: usize§num_non_resident: usize§capacity_non_resident: usize§weighter: We§lifecycle: L

Implementations§

Source§

impl<Key, Val, We, B, L, Plh: SharedPlaceholder> CacheShard<Key, Val, We, B, L, Plh>

Source

pub fn remove_placeholder(&mut self, placeholder: &Plh)

Source

fn cold_change_weight( &mut self, idx: NonZeroU32, old_weight: u64, new_weight: u64, )

Source§

impl<Key, Val, We, B, L, Plh> CacheShard<Key, Val, We, B, L, Plh>

Source

pub fn memory_used(&self) -> MemoryUsed

Source

pub fn weight(&self) -> u64

Source

pub fn len(&self) -> usize

Source

pub fn capacity(&self) -> u64

Source

pub fn clear(&mut self)

Source

pub fn drain(&mut self) -> impl Iterator<Item = (Key, Val)> + '_

Source

pub fn iter(&self) -> impl Iterator<Item = (&Key, &Val)> + '_

Source

pub fn iter_from( &self, continuation: Option<NonZeroU32>, ) -> impl Iterator<Item = (NonZeroU32, &Key, &Val)> + '_

Source§

impl<Key: Eq + Hash, Val, We: Weighter<Key, Val>, B: BuildHasher, L: Lifecycle<Key, Val>, Plh: SharedPlaceholder> CacheShard<Key, Val, We, B, L, Plh>

Source

pub fn new( hot_allocation: f64, ghost_allocation: f64, estimated_items_capacity: usize, weight_capacity: u64, weighter: We, hash_builder: B, lifecycle: L, ) -> Self

Source

pub fn reserve(&mut self, additional: usize)

Reserver additional space for additional entries. Note that this is counted in entries, and is not weighted.

Source

pub fn retain<F>(&mut self, f: F)
where F: Fn(&Key, &Val) -> bool,

Source

fn hash_static<Q>(hasher: &B, key: &Q) -> u64
where Q: Hash + Equivalent<Key> + ?Sized,

Source

pub fn hash<Q>(&self, key: &Q) -> u64
where Q: Hash + Equivalent<Key> + ?Sized,

Source

fn search<Q>(&self, hash: u64, k: &Q) -> Option<NonZeroU32>
where Q: Hash + Equivalent<Key> + ?Sized,

Source

fn search_resident<Q>( &self, hash: u64, k: &Q, ) -> Option<(NonZeroU32, &Resident<Key, Val>)>
where Q: Hash + Equivalent<Key> + ?Sized,

Source

pub fn contains<Q>(&self, hash: u64, key: &Q) -> bool
where Q: Hash + Equivalent<Key> + ?Sized,

Source

pub fn get<Q>(&self, hash: u64, key: &Q) -> Option<&Val>
where Q: Hash + Equivalent<Key> + ?Sized,

Source

pub fn get_mut<Q>( &mut self, hash: u64, key: &Q, ) -> Option<RefMut<'_, Key, Val, We, B, L, Plh>>
where Q: Hash + Equivalent<Key> + ?Sized,

Source

pub fn peek_token(&self, token: NonZeroU32) -> Option<&Val>

Source

pub fn peek_token_mut( &mut self, token: NonZeroU32, ) -> Option<RefMut<'_, Key, Val, We, B, L, Plh>>

Source

pub fn peek<Q>(&self, hash: u64, key: &Q) -> Option<&Val>
where Q: Hash + Equivalent<Key> + ?Sized,

Source

pub fn peek_mut<Q>( &mut self, hash: u64, key: &Q, ) -> Option<RefMut<'_, Key, Val, We, B, L, Plh>>
where Q: Hash + Equivalent<Key> + ?Sized,

Source

pub fn remove<Q>(&mut self, hash: u64, key: &Q) -> Option<(Key, Val)>
where Q: Hash + Equivalent<Key> + ?Sized,

Source

pub fn remove_if<Q, F>( &mut self, hash: u64, key: &Q, f: F, ) -> Option<(Key, Val)>
where Q: Hash + Equivalent<Key> + ?Sized, F: FnOnce(&Val) -> bool,

Source

pub fn remove_token(&mut self, token: NonZeroU32) -> Option<(Key, Val)>

Source

pub fn remove_next( &mut self, continuation: Option<NonZeroU32>, ) -> Option<(NonZeroU32, Key, Val)>

Source

fn remove_internal(&mut self, hash: u64, idx: NonZeroU32) -> Option<(Key, Val)>

Source

fn advance_cold(&mut self, lcs: &mut L::RequestState) -> bool

Advance cold ring, promoting to hot and demoting as needed.

Source

fn advance_hot(&mut self, lcs: &mut L::RequestState) -> bool

Advance hot ring evicting entries.

Source

fn advance_ghost(&mut self)

Source

fn insert_existing( &mut self, lcs: &mut L::RequestState, idx: NonZeroU32, key: Key, value: Val, weight: u64, strategy: InsertStrategy, ) -> Result<(), (Key, Val)>

Source

fn map_insert(&mut self, hash: u64, idx: NonZeroU32)

Source

fn map_remove(&mut self, hash: u64, idx: NonZeroU32)

Source

pub fn replace_placeholder( &mut self, lcs: &mut L::RequestState, placeholder: &Plh, referenced: bool, value: Val, ) -> Result<(), Val>

Source

fn handle_overweight_replace_placeholder( &mut self, lcs: &mut L::RequestState, placeholder: &Plh, key: Key, value: Val, ) -> Result<(), Val>

Source

pub fn insert( &mut self, lcs: &mut L::RequestState, hash: u64, key: Key, value: Val, strategy: InsertStrategy, ) -> Result<(), (Key, Val)>

Source

fn handle_insert_overweight( &mut self, lcs: &mut L::RequestState, hash: u64, key: Key, value: Val, strategy: InsertStrategy, ) -> Result<(), (Key, Val)>

Source

pub fn upsert_placeholder<Q>( &mut self, hash: u64, key: &Q, ) -> Result<(NonZeroU32, &Val), (Plh, bool)>
where Q: Hash + Equivalent<Key> + ToOwned<Owned = Key> + ?Sized,

Source

pub fn set_capacity(&mut self, new_weight_capacity: u64)

Trait Implementations§

Source§

impl<Key: Clone, Val: Clone, We: Clone, B: Clone, L: Clone, Plh: Clone> Clone for CacheShard<Key, Val, We, B, L, Plh>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<Key, Val, We, B, L, Plh> Freeze for CacheShard<Key, Val, We, B, L, Plh>
where B: Freeze, We: Freeze, L: Freeze,

§

impl<Key, Val, We, B, L, Plh> RefUnwindSafe for CacheShard<Key, Val, We, B, L, Plh>

§

impl<Key, Val, We, B, L, Plh> Send for CacheShard<Key, Val, We, B, L, Plh>
where B: Send, We: Send, L: Send, Key: Send, Val: Send, Plh: Send,

§

impl<Key, Val, We, B, L, Plh> Sync for CacheShard<Key, Val, We, B, L, Plh>
where B: Sync, We: Sync, L: Sync, Key: Sync, Val: Sync, Plh: Sync,

§

impl<Key, Val, We, B, L, Plh> Unpin for CacheShard<Key, Val, We, B, L, Plh>
where B: Unpin, We: Unpin, L: Unpin, Key: Unpin, Val: Unpin, Plh: Unpin,

§

impl<Key, Val, We, B, L, Plh> UnwindSafe for CacheShard<Key, Val, We, B, L, Plh>
where B: UnwindSafe, We: UnwindSafe, L: UnwindSafe, Key: UnwindSafe, Val: UnwindSafe, Plh: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.