Least Frequently Used (LFU)

The last common algorithm you can meet in caches is the LFU algorithm. Like the LRU algorithm, this flavor also maintains statistics on the cache access.

The main difference with LRU is that, instead of using a time-based statistic, it uses a frequency statistic. It means that if E1 is accessed 10 times and E2 is accessed 5 times, then E2 will be evicted before E1.

The issue with this algorithm is that if you have a fast access rate during a small period of time, then you may evict a more regularly used element than the one often used during a very short period of time. So, the final cache distribution may not be that optimal.

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.