Skip to main content

SharedLRUCache

Struct SharedLRUCache 

Source
pub struct SharedLRUCache<K: Copy + Eq + Default + 'static, V: Copy + Default + 'static> { /* private fields */ }

Implementations§

Source§

impl<K: Copy + Eq + Default + 'static, V: Copy + Default + 'static> SharedLRUCache<K, V>

Source

pub fn create( base_path: impl AsRef<Path>, capacity: u32, ) -> Result<Self, LRUError>

Create a new LRU cache with capacity entries.

SIZING: the underlying SharedHashMap is sized to 8x capacity to absorb tombstone accumulation (open-addressing leaves a tombstone on every remove; LRU caches do many removes via eviction). The linked list region is sized to capacity + 2 (one sentinel head + capacity nodes + 1 spare for the pop-then-push transition during update).

Source

pub fn open( base_path: impl AsRef<Path>, capacity: u32, ) -> Result<Self, LRUError>

Source

pub fn capacity(&self) -> u32

Source

pub fn len(&self) -> usize

Current number of entries.

Source

pub fn is_empty(&self) -> bool

Source

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

Lock-free lookup. Does NOT promote k to MRU position. Use get_and_touch or touch for strict LRU semantics.

Source

pub fn contains_key(&self, key: &K) -> bool

True if key is present (lock-free).

Source

pub fn touch(&self, key: &K) -> bool

Promote key to MRU position. Writer-side. Returns true if the key was present and was promoted.

Source

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

Look up and promote in one call. Writer-side.

Source

pub fn put(&self, key: K, value: V) -> Result<Option<V>, LRUError>

Insert / update. Writer-side. If the cache is at capacity AND key is new, evicts the LRU entry first. Returns the previous value if key was present.

Source

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

Remove a key. Writer-side. Returns the value if present.

Source

pub fn evict_oldest(&self) -> Option<(K, V)>

Evict the LRU (least-recently-used) entry. Writer-side. Returns (key, value) of the evicted entry, or None if empty.

Source

pub fn snapshot_mru_first(&self) -> Vec<(K, V)>

Snapshot all entries from MRU (front) to LRU (back). Lock-free; not stable under concurrent writers.

Source

pub fn snapshot_lru_first(&self) -> Vec<(K, V)>

Snapshot all entries from LRU (back) to MRU (front).

Source

pub fn flush(&self) -> Result<(), LRUError>

Source

pub fn flush_async(&self) -> Result<(), LRUError>

Trait Implementations§

Source§

impl<K: Copy + Eq + Default + Send + Sync + 'static, V: Copy + Default + Send + Sync + 'static> AdaptiveInstance for SharedLRUCache<K, V>

Source§

fn header(&self) -> &HandshakeHeader

Source§

fn ring(&self) -> &ObservationRing

Source§

fn make_policy(&self) -> Box<dyn Policy>

Source§

fn apply_migration(&self, new_tag: u32)

Called by the sidecar when the policy returns a new strategy tag. Default implementation: just set the tag on the header. Primitives that need heavier migration (data-layout swap) override this to perform the swap before (or after) updating the tag.

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