pub struct EntityCache { /* private fields */ }Expand description
Sharded, bounded LRU cache for UnifiedStore::get_any lookups.
Implementations§
Source§impl EntityCache
impl EntityCache
pub fn new() -> Self
pub fn with_capacity(total_capacity: usize) -> Self
Sourcepub fn get(&self, key: u64) -> Option<(String, UnifiedEntity)>
pub fn get(&self, key: u64) -> Option<(String, UnifiedEntity)>
Cache lookup. Updates hits / misses.
Acquires the shard write lock on a hit (LRU touch needs it). If the touch cost ever shows up in profiles we can split into a fast read-only probe + deferred touch, but at shard size ≈ 625 it’s not the bottleneck.
Sourcepub fn insert(&self, key: u64, value: (String, UnifiedEntity))
pub fn insert(&self, key: u64, value: (String, UnifiedEntity))
Insert. Counts evictions for observability.
Sourcepub fn remove(&self, key: u64) -> bool
pub fn remove(&self, key: u64) -> bool
Remove a single key. Returns true if the key was present.
Hot path on delete_batch / delete. Probes with a read lock first:
most deletes target rows that were never read, so the cache miss case
avoids the write-lock acquisition entirely. This is the load-bearing
optimisation for #85’s delete_sequential regression — the original
code took the write lock unconditionally, even for a 100 % miss
workload.
Sourcepub fn remove_many(&self, keys: impl IntoIterator<Item = u64>)
pub fn remove_many(&self, keys: impl IntoIterator<Item = u64>)
Bulk remove. Same fast-path optimisation as remove: skip the
shard’s write lock entirely when none of its candidate keys are
present.
Sourcepub fn retain<F>(&self, keep: F)
pub fn retain<F>(&self, keep: F)
Drop every entry whose (collection, entity) value fails keep.
Used by collection-drop paths.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Total entries across all shards. Diagnostic only — locks every shard.
Sourcepub fn hit_rate(&self) -> Option<f64>
pub fn hit_rate(&self) -> Option<f64>
Hit / (hit + miss). Returns None if no lookups have occurred.
Sourcepub fn stats(&self) -> EntityCacheStats
pub fn stats(&self) -> EntityCacheStats
Snapshot of the three counters: (hits, misses, evictions).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for EntityCache
impl !RefUnwindSafe for EntityCache
impl Send for EntityCache
impl Sync for EntityCache
impl Unpin for EntityCache
impl UnsafeUnpin for EntityCache
impl UnwindSafe for EntityCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more