Hi I'm doing some research after a concurrent dictionary with expiration features.
We have a list of objects that are accessed with adds and removes from a lot different threads. We also want an expiration time on the items for like lets say 60 secconds. (It would be nice if we can listen on an event that tells us which items that has been expired and removed from the list).
We also need the lookup to be really fast like an Dictionary.
The list will contain houndred of thousands objects.
So its like an ConcurrentDictionary but with expiration features.
Can MemoryCache be something?
Or are they other things to look on?
ConcurrentDictionary<TKey,TValue> is designed for multithreaded scenarios. You do not have to use locks in your code to add or remove items from the collection. However, it is always possible for one thread to retrieve a value, and another thread to immediately update the collection by giving the same key a new value.
adjective. occurring or existing simultaneously or side by side: concurrent attacks by land, sea, and air. acting in conjunction; cooperating: the concurrent efforts of several legislators to pass the new law. having equal authority or jurisdiction: two concurrent courts of law.
The biggest reason to use ConcurrentDictionary over the normal Dictionary is thread safety. If your application will get multiple threads using the same dictionary at the same time, you need the thread-safe ConcurrentDictionary , this is particularly true when these threads are writing to or building the dictionary.
Represents a thread-safe collection of key/value pairs that can be accessed by multiple threads concurrently.
MemoryCache
looks ideal, especially as
This type is thread safe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With