I'm trying to keep an in-memory list of entries in my .NET cache, representing the last N HTTP requests to my app. What's the best .NET sequence to use for this?
Requirements
- Fixed number of items (e.g 50)
- Serializable (need to add sequence to .NET cache)
- When i try and add the max+1 entry, it automatically removes the oldest item in order to make room
- Don't really care about order of items
- Need to be able to get all items in a single operation, in order to perform aggregate calculations.
- Thread-safe
- Non-unique (e.g
List<T>
, notDictionary<TKey,TValue>
). I might hit the URL/foo
10x times, which isn't unique but all needs to be added to the sequence.
Off the top of my head, i was thinking i could use a Queue<T>
, and when enqueuing just check the length, and if it hits the capacity, dequeue the old one. But concerned about thread safety (ConcurrentQueue<T>
perhaps?) and the best approach, since this is a 'hot' area of my app that needs to be optimal.
Thanks!