Expand description
Shared primitives for size-bounded in-memory caches.
The concrete caches in this crate (crate::oembed_cache,
video_metadata_cache, video_transcode_cache) all bound memory by an
approximate byte budget with the same conventions:
- A
max_size_bytesof0disables the cache entirely. - Each stored entry is weighed once at insert time (value estimate + key bytes + fixed per-entry overhead).
- Overwriting an existing key subtracts the replaced entry’s accounted size first, so the running total reflects the replacement rather than ratcheting upward.
- When the total exceeds the budget, entries are evicted in a caller-defined priority order until enough bytes are freed.
SizeBoundedMap implements those conventions on top of a lock-free
papaya HashMap with an AtomicUsize size counter, and is the shared
core for the papaya-backed caches. Entry carries the per-entry
bookkeeping and is also reused by the mutex-guarded LRU oembed cache,
which shares the weighing/accounting conventions but not the storage.
Structs§
- Entry
- A cached value together with the bookkeeping used for size accounting and insertion-order eviction.
- Eviction
Stats - Statistics from an eviction pass.
- Size
Bounded Map - A lock-free, size-bounded concurrent map.
Enums§
- Claim
- Outcome of
SizeBoundedMap::claim_or.