pub struct LfuCache<K, V> { /* private fields */ }Implementations§
Source§impl<K, V> LfuCache<K, V>
impl<K, V> LfuCache<K, V>
pub fn new(max_entries: Option<usize>) -> Self
Sourcepub fn with_byte_limit(
max_entries: Option<usize>,
max_bytes: Option<usize>,
) -> Self
pub fn with_byte_limit( max_entries: Option<usize>, max_bytes: Option<usize>, ) -> Self
A byte-limited cache requires insert_weighted with conservative heap
charges for both key and value. Table storage is charged separately.
Sourcepub fn with_byte_limits(
max_entries: Option<usize>,
max_bytes: Option<usize>,
max_entry_bytes: Option<usize>,
) -> Self
pub fn with_byte_limits( max_entries: Option<usize>, max_bytes: Option<usize>, max_entry_bytes: Option<usize>, ) -> Self
Bound both aggregate retention and one key/value entry. The per-entry limit includes its inline layout; the aggregate additionally accounts for spare hash-table capacity. Zero disables retention.
pub fn get(&mut self, key: &K) -> Option<V>
pub fn record_bypass(&mut self)
pub fn record_rejected_admission(&mut self)
Sourcepub fn insert(&mut self, key: K, value: V)
pub fn insert(&mut self, key: K, value: V)
Legacy count-only admission. Byte-limited caches refuse this path so callers cannot accidentally retain an uncharged key/value payload.
Sourcepub fn insert_weighted(&mut self, key: K, value: V, heap_charge: usize) -> bool
pub fn insert_weighted(&mut self, key: K, value: V, heap_charge: usize) -> bool
Charge owned heap retained through the key/value, excluding their inline bucket layout. Rejected admissions leave an existing entry unchanged. In-flight cloned values are owned by callers, outside this cache bound. Returns whether admission checks accepted the entry. Subsequent LFU eviction can still remove it; this does not promise a future cache hit.
pub fn max_bytes(&self) -> Option<usize>
Sourcepub fn charged_bytes(&self) -> Option<usize>
pub fn charged_bytes(&self) -> Option<usize>
Conservative requested-heap charge, including spare hash-table capacity.
The pinned hashbrown table uses at most twice its original advertised
capacity in buckets plus control bytes/alignment. Preserve the high-water
capacity: tombstones can lower HashMap::capacity() without freeing its
allocation. This excludes allocator rounding,
the fixed cache object and heap owned by callers after cloning a value.