Expand description
TTL-based cache with automatic expiry.
This module provides TtlCache, a capacity-bounded cache where each
entry carries an expiry deadline expressed as seconds since an arbitrary
epoch (e.g. SystemTime::UNIX_EPOCH). Expired entries are never returned
and can be purged in bulk via TtlCache::remove_expired.
The caller is responsible for supplying monotonically-increasing
now_secs timestamps; this keeps the implementation deterministic and
easy to unit-test without std::time side-effects.
§Example
use oximedia_cache::ttl_cache::TtlCache;
let mut cache: TtlCache<&str, Vec<u8>> = TtlCache::new(64, 30);
cache.insert("frame-001", vec![0u8; 128], 1_000);
assert!(cache.get(&"frame-001", 1_020).is_some()); // within TTL
assert!(cache.get(&"frame-001", 1_031).is_none()); // expiredStructs§
- TtlCache
- Capacity-bounded TTL cache.
- TtlCache
Stats - Snapshot of
TtlCachestatistics. - TtlEntry
- A single cache entry with an embedded TTL deadline.