High-performance cache policies and supporting data structures.
Feature: policy-lifo
Evict the most recently inserted entry.
LIFO uses a stack structure:
Think of it like a stack of plates - you remove the one you just added.
In cachekit, src/policy/lifo.rs uses:
HashMap<K, V> for O(1) lookupVec<K> as stack for insertion orderget(key)insert(key, value)key exists: update value in place, no stack changeLIFO is a niche policy - only use when you have specific evidence that newest items are least valuable:
Undo Buffer Pattern:
- User does Action A (cached)
- User does Action B (cached)
- User does Action C (cached)
- User hits Undo → Action C discarded (most recent)
LIFO is perfect: most recent action discarded first
Typical Access Pattern:
- Insert page A
- Insert page B
- Insert page C
- Access page C again ← but it was just evicted!
LIFO evicted the item we just added and immediately needed
LRU/FIFO would be much better
| Policy | Evicts | Good For | Common? |
|---|---|---|---|
| FIFO | Oldest insert | Predictable order | Common |
| LIFO | Newest insert | Temporary/undo buffers | Very rare |
| LRU | Least recent | Temporal locality | Very common |
| Random | Random | Baseline | Rare |
LIFO is the opposite of FIFO and much less intuitive for most use cases.
cachekitStack-based with Vec:
Vec<K>: Stack of keys (push/pop from end)HashMap<K, V>: Value storage