Feature: policy-fifo
Evict the oldest inserted resident entry when the cache is full.
Typical O(1) FIFO implementation:
HashMap<K, V>for key lookup and storageVecDeque<K>(or ring buffer) to track insertion order
In cachekit, FIFO is implemented in src/policy/fifo/ with:
- a key/value map plus an insertion-order queue
- lazy stale entry handling (queue entries can become stale if the key is removed/updated)
- If
keyalready exists: update the stored value, do not change insertion order. - If cache is at capacity: evict from the front of the queue until a live key is found.
- Insert the new key/value and push the key to the back of the queue.
- Lookup only; FIFO does not reorder on access.
- Pop from queue front until you find a key still present in the map; remove it from the map and return it.
- Lookup: O(1)
- Insert: O(1) amortized; eviction may skip stale queue entries
- Memory:
HashMap+ queue of keys
- Stale keys: if you support
remove(key)(or “update” that replaces storage), you must reconcile the queue.- Eager cleanup requires O(n) removal from the middle of a
VecDeque. - Lazy cleanup keeps hot path O(1) and pays cleanup during eviction.
- Eager cleanup requires O(n) removal from the middle of a
- Duplicate keys in queue: if your update path pushes keys again, you must handle duplicates on eviction; the repo implementation avoids changing order on update.