The LRU Cache Data Structure
This whole LRU thing sounds great in theory. But now we have to grapple with another issue: how do we track which items were least recently used?
In the previous walk-through of LRU, we looked back at past requests to see which ones were made recently and which ones hadn’t been made in a while. Now, that would mean that we’d have to somehow save our past requests somewhere. But if we save all our requests, we defeat the entire purpose of an eviction policy, which is to free up memory! It doesn’t help to evict items from the cache if we end up saving the same items somewhere else. A better approach is to somehow indicate within the cache itself which items were recently requested and which weren’t.
There are several ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access