In which case LFU is better than LRU?

Viewed 2587

I have been trying to find a good case in which LFU is better than LRU but I am not sure for that.

What I have managed to do (but not sure if it is a good example) is the case when you have a cache with capacity 3 and the cache requests are 4 (like A B C D) but C and D are requested more often.

So if the request stream was A B C D C A D B D C A B A C D LRU will produce 10 faults but LFU will produce 9 faults.

Is this an accepted case??

2 Answers

It may happen that some data was popular in the past and currently becomes temporarily irrelevant, but then it will likely be accessed again in the near future.

Think about an online retailer store. Let's say some of their best selling items are camera, phone etc.If Valentine's day is around the corner, people are going to order gifts for Valentine's day. So if you implemented LRU cache, Least Recently Used cache, it will purge your best selling items from the cache.

enter image description here

While LRU policy never guarantees that best-selling items will stay in the cache, the higher frequency with which they are accessed makes it more likely that they will stay in the cache (because it is likely they will go to the head of the queue before being purged). During a peak, if the number of items that suddenly become popular is large enough, they could fill the cache and force the usual items to be purged. This would be a temporary side effect that will regress after the peak. In some situations, this could also be desirable, because items popular during a peak should be accessed faster than the regular best-selling ones.

Related