I currently am using a ConcurrentDictionary
to hold a collection of login names that have authenticated with my API. I do this to prevent duplicate logins from other web clients (a requirement of the system architecture). If a user authenticates with a login that is already "logged in" they are given a choice ...
- Continue and the previous login will be expired
- Cancel and the current session will be logged out
I am using a ConcurrentDictionary
because it is supposed to be thread safe which is important in an environment where multiple clients are accessing the API.
What I am asking is if the ConcurrentDictionary
is needed because I am running into trouble deleting all items in the collection that match a given key. Is a ConcurrentDictionary
called for in this case? If not, would a plain Dictionary
suffice? If not, and a ConcurrentDictionary
is needed is there a method that will remove all entries matching a given key? All I can see is TryRemove()
which only seems to remove a single entry.