LRU (Least Recently Used) キャッシュは、容量に達したときに最も長時間アクセスされていないアイテムを削除します。古典的な設計はハッシュマップ(O(1)ルックアップ)と双方向リンクリスト(O(1)再配列)を組み合わせ、O(1)のgetとputを実現します。
2つの構造の設計
text
HashMap: key -> node DLL (recency order):
MRU <-> ... <-> LRU
get/put: map finds node move touched node to front (MRU)
in O(1); DLL splices it evict the tail (LRU) when full
to the front in O(1)
