Least Recently Used (LRU) Cache

Viewed 2139

I know that I can use various container classes in STL but it's an overkill and expensive for this purpose.

We have over 1M+ users online and per user we need to maintain 8 unrelated 32-bit data items. The goal is to

  1. find if an item exists in the list,
  2. if not, insert. Remove oldest entry if full.

Brute Force approach would be to maintain a last write pointer and iterate (since only 8 items) but I am looking for inputs to better analyze and implement.

Look forward to some interesting suggestions in terms of design pattern and algorithm.

6 Answers
Related