Apologize in advance for poor wording and a complicated question, English is me second language.
I'm looking for a data structure to hold an array/list/collection of objects (in my case - integer IDs - but that doesn't matter), that would track the "usage frequency" of the elements. So I can run a background job and remove lesser-used elements (to free up memory usage).
Something like, when an element is accessed or searched for - the element is moved "to the surface", pushing less used elements "to the bottom". Again, the goal is to determine "lesser accessed" values and remove them from time to time.
I was thinking about writing my own class, inheriting/subclassing some existing list structure (LinkedList<T,T>
or Queue<T>
maybe) and then overload some "GetElement" method so that it would "return the element AND move it to the beginning of the list". So later, in my background job, I can remove the elements from the "end of the list" (b/c they are accessed less frequent).
- Am I in the right direction?
- Is there any built-in data structure in .NET for this or some well-known practice maybe? I tried googling, haven't found anything. But I bet this problem is as old as the history of computing :)
Thank you!
UPDATE: thanks for the comments. Turns out "LRU" is what it's called in plain English. I'm closing this question, since googling for "LRU cache c#" offers tons of answers.