pub struct ByteLruCache<K: Eq + Hash + Clone, V> { /* private fields */ }Expand description
Byte-limited LRU cache with an optional entry cap.
Unlike an entry-count-limited LRU, this cache tracks the resident byte cost
of each value (via ResidentBytes) and evicts the least-recently-used
entries until the total resident bytes fit under max_bytes. This is the
correct policy for biobank-scale payloads where a single cache entry (e.g.
an n*K distance matrix) can itself be multiple gigabytes and an entry-count
cap would silently blow the memory budget. Small entry caps are still useful
for payloads with known shape, such as owned PC data matrices shared across
model blocks.
Implementations§
Source§impl<K: Eq + Hash + Clone, V: Clone + ResidentBytes> ByteLruCache<K, V>
impl<K: Eq + Hash + Clone, V: Clone + ResidentBytes> ByteLruCache<K, V>
pub fn new(max_bytes: usize) -> Self
pub fn with_max_entries(max_bytes: usize, max_entries: usize) -> Self
pub fn get(&self, key: &K) -> Option<V>
pub fn insert(&self, key: K, value: V)
pub fn resident_bytes(&self) -> usize
pub const fn max_bytes(&self) -> usize
pub fn len(&self) -> usize
pub fn clear(&self)
Trait Implementations§
Auto Trait Implementations§
impl<K, V> !Freeze for ByteLruCache<K, V>
impl<K, V> RefUnwindSafe for ByteLruCache<K, V>
impl<K, V> Send for ByteLruCache<K, V>
impl<K, V> Sync for ByteLruCache<K, V>
impl<K, V> Unpin for ByteLruCache<K, V>
impl<K, V> UnsafeUnpin for ByteLruCache<K, V>
impl<K, V> UnwindSafe for ByteLruCache<K, V>
Blanket Implementations§
impl<T> Allocation for T
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
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>
Converts
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>
Converts
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.