I am trying to keep a list of records in memory in the .NET cache by submitting the last N HTTP requests to my application. What is the best .NET sequence used for this?
Requirements
- Fixed number of items (e.g. 50)
- Serializable (need to add sequence to .NET cache)
- When I try to add a max + 1 entry, it automatically deletes the oldest item to make room
- Really do not care about the order of things.
- You need to be able to get all the elements in one operation in order to perform aggregate calculations.
- thread safe
- Non-historical (e.g.
List<T>
, not Dictionary<TKey,TValue>
). I could hit the URL /foo
10 times, which is not unique, but everything needs to be added to the sequence.
Up to the head, I thought I could use it Queue<T>
, and when enqueuing just checks the length, and if it falls into the container, delete the old one. But worry about thread safety ( ConcurrentQueue<T>
maybe?) And the best approach, since this is the “hot” area of my application that should be optimal.
Thank!
source
share