KEEP OR EVICT
Make room for
what comes next.
Serve a visible queue of requests from a tiny shelf. A hit is free. A miss costs the item's retrieval price. When the shelf is full, choose one resident item to evict before bringing in the requested item.
Your cost
Target ≤
LRU so far
Offline optimum
The full request queue
Look ahead. A costly item may be worth keeping even if it will be used later.
Your shelf
On a full-shelf miss, select an eviction card before serving. A hit refreshes recency; your manual eviction choice overrides LRU.
The policy behind the comparison
Your shelf and the automatic least-recently-used baseline use the actual LRUCache library. The baseline always evicts the item untouched for longest. Your shelf lets you override that choice. The offline optimum uses dynamic programming over the full visible queue and weighted retrieval costs; every miss must retain the new item.
Source: isaacs/node-lru-cache11.5.3 · BlueOak-1.0.0 · 5,917 stars observed30October2026. Browser diagnostics adapter supplied by upstream. Original challenges and GPT item art. License