pub struct MemoryCacheStore { /* private fields */ }Expand description
In-memory CacheStore with optional TTL and LRU eviction.
Default constructor builds an unbounded store (no TTL, no LRU). Use
Self::builder to opt in to limits — e.g.
MemoryCacheStore::builder().max_entries(256).max_age(Duration::from_secs(60)).build().
Eviction is checked lazily on get (expired entries are removed) and on
put (over-capacity entries are dropped, least-recently-used first). LRU
is approximated with a monotonic counter — no doubly-linked list — which
keeps the struct small at the cost of O(n) eviction. That’s fine for the
caches we expect (≤ a few hundred entries).
Implementations§
Source§impl MemoryCacheStore
impl MemoryCacheStore
Sourcepub fn builder() -> MemoryCacheStoreBuilder
pub fn builder() -> MemoryCacheStoreBuilder
Start a builder for an LRU- / TTL-bounded store.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of entries currently cached.
Note: this does not prune expired entries first. Use
Self::is_empty or a fresh get to trigger pruning if needed.
§Panics
Panics if the internal mutex was poisoned by a prior panic.