1

Java has a really useful feature in LinkedHashMap. A member function removeEldestEntry() where you can return true when the hash is over N entries. Great way to easily declare a LRU cache.

Is there anything like this in .NET?

Edit: The question here does not answer this as that solution does not provide the functionality in removeEldestEntry().

Community
  • 1
  • 1
David Thielen
  • 28,723
  • 34
  • 119
  • 193
  • Possible duplicate of [C# equivalent of LinkedHashMap](http://stackoverflow.com/questions/29205934/c-sharp-equivalent-of-linkedhashmap) – cemal Aug 18 '16 at 12:48
  • @cemal - that solution does not have the functionality removeEldestEntry(). – David Thielen Aug 18 '16 at 13:47
  • What about creating your pairs and adding them into a queue as suggested in http://stackoverflow.com/a/13998338/4606005 – cemal Aug 18 '16 at 13:52
  • @cemal yes I can put them in both a queue and a hashmap. I was hoping to avoid having two collections. Also, with this solition, each time an item is accessed in the hashmap, it has to be moved in the queue. That's expensive. – David Thielen Aug 18 '16 at 13:54
  • Which are you actually wanting to find the equivalent, a true/false stating if the eldest entry should be removed or the action of removing the eldest entry based on the result of that check? If you are wanting LRU cache behavior, just use the [`MemoryCache`](https://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396) class, you can configure it to evict LRU entries. – Scott Chamberlain Aug 18 '16 at 14:07

0 Answers0