High-performance cache policies and supporting data structures.
TTL is not a replacement policy; it’s an expiration rule that often coexists with an eviction policy.
Store expires_at per entry.
get: if expired, remove and treat as miss.insert: set expires_at = now + ttl.Pros: no background work. Cons: expired entries can occupy space until touched.
Maintain an expiration index:
expires_at (lazy stale entries), orPros: can proactively free space. Cons: extra metadata and background/maintenance work.
When cache is full: