Skip to main content

Module cache

Module cache 

Source
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_bytes of 0 disables 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.
EvictionStats
Statistics from an eviction pass.
SizeBoundedMap
A lock-free, size-bounded concurrent map.

Enums§

Claim
Outcome of SizeBoundedMap::claim_or.