Hacker News new | ask | show | jobs
by vidarh 895 days ago
Look at the animation. The description is confusing.

It uses a list that's treated as a ring buffer to keep track of keys currently in the cache.

The "hand" is a pointer that points to a given node in that ring buffer.

When the cache is full and a space is needed, the "hand" moves through that buffer (possibly wrapping around). Whenever it points at a node that hasn't been touched since the last time it was seen, that node is evicted and you're done for this time, otherwise it clears the visited bit for that node and keeps going.

(You're always guaranteed to find a node to evict, because worst case you scan through the entire set of nodes, and find the first node you cleared the visited bit of)