Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does cache use Most Recently Used (MRU) algorithm as evict policy?

I know the algorithms of MRU and its reversed one Least Recently Used (LRU).

I think LRU is reasonable, as LRU element means it will be used at least possible in future. However, MRU element means the element is very possible to be used in future, why evict it? What is the reasonable scenario?

like image 277
卢声远 Shengyuan Lu Avatar asked Feb 23 '11 07:02

卢声远 Shengyuan Lu


People also ask

What eviction policy would you use for that cache?

LRU (or Least Recently Used) is a cache eviction strategy, wherein if the cache size has reached the maximum allocated capacity, the least recently accessed objects in the cache will be evicted.

What is MRU cache?

Most Recently Used (MRU): This cache algorithm removes the most recently used items first. A MRU algorithm is good in situations in which the older an item is, the more likely it is to be accessed.

What are the two eviction policies for cache memory?

There are a lot of eviction policies: - FIFO (First In First Out), LIFO (Last In First Out) — I think it doesn't need to be explained. - LRU (Least Recently Used) — discards items that have not been used for a long time (more than other elements in the cache).

What is replacement algorithm of cache memory Why is it used?

Cache replacement algorithms are used to optimize the time taken by processor to process the information by storing the information needed by processor at that time and possibly in future so that if processor needs that information, it can be provided immediately.


2 Answers

Imagine you were looking up the details of buses as they arrived at a bus stop, based on their bus number (or whatever identifier you use).

It's somewhat reasonable to think that if you've just seen a number 36 bus, you're less likely to see another one imminently than to see one of the other buses that stops there.

Just one example, but the idea is more general: in some cases, having "just seen something" is a good indicator that you're unlikely to see the same thing again soon.

like image 82
Jon Skeet Avatar answered Sep 23 '22 02:09

Jon Skeet


Perhaps a more tangible example would be a media server. When the user has completed watching a video (let's say it's an episode of a TV show), they are presumably the least likely to want to view it again. So if you must evict something, evict the most recently viewed item.

In practice though, I believe this type of cache is typically used in addition to an LRU or LFU cache, where the two caches in tandem allow you to cover a wide variety of cases.

like image 22
Kyle Chadha Avatar answered Sep 22 '22 02:09

Kyle Chadha