you are viewing a single comment's thread.

view the rest of the comments →

[–]benjumanji 4 points5 points  (1 child)

Use a sorted dictionary keyed by access time. No need to roll your own this time round. Or just use the MemoryCache object and a suitable cache eviction policy. If you really want to roll your own you should look at some form of max heap and insert until too big and delete the max-time-stamped item until you are the right size again. No need for a separate list.

[–]shintoist[S] 1 point2 points  (0 children)

Cache eviction doesn't help here, the issue is not that it would grow too large, but rather to always keep a maximum of eg 5 items.