LRU, MRU & Min Key
Anonymous User
410

Hi Guys,
I am trying to figure out they best way to implement this cache problem.
I need to maintain a cache in some kind of DS and evict elements from it based on what algo is asked for.

Currently I am using a HashMap (OrderedDict). If an element is accessed, I remove that element and add it to the end of HashMap. If LRU is called for eviction, I remove the 1st item in the HashMap, and the last item for MRU.

Now, the issue is I need to remove the item based on it's key (min key). Sorting the hashmap based on keys everytime eviction is called, doesn't sound optimized.
Is there any other way I can maintain the cache, so I can get LRU, MRU and min key based evictions?

Comments (1)