High-performance cache policies and supporting data structures.
Feature: policy-mru
Evict the most recently accessed entry.
MRU is the opposite of LRU:
This is useful for specific cyclic or sequential access patterns where the most recently accessed item is unlikely to be accessed again soon.
In cachekit, src/policy/mru.rs uses:
HashMap<K, NonNull<Node<K,V>>> for O(1) key lookupget(key)insert(key, value)key exists: update value in place, preserve positionMRU is only beneficial for specific access patterns:
Cyclic Pattern (database index scans):
Access: Index A → Index B → Index C → Index A → Index B → Index C → ...
MRU behavior:
- Each access moves item to MRU (head)
- When cache full, evict most recent (which won't be needed for 2 more accesses)
- LRU would be worse here (would evict item about to be reused)
Temporal Locality (typical workload):
Access: page1, page1, page1, page2, page3, page1, page1, ...
MRU behavior:
- page1 accessed frequently → moves to MRU → gets evicted!
- Terrible performance
- LRU would be much better
cachekitIf you already have an LRU structure (recency-ordered list):
So MRU is “LRU, but evict from head instead of tail”.
| Policy | Eviction Point | Best For | Risk |
|---|---|---|---|
| LRU | Tail (LRU) | Temporal locality | Scan pollution |
| MRU | Head (MRU) | Cyclic/sequential patterns | Evicts frequently used items |
| SLRU | Probation LRU | Scan resistance | Tuning required |
| FIFO | Oldest | Predictable order | No adaptation |
Uses intrusive pointers (NonNull<Node<_>>):