I can't see much sense with concurrent collection in the case, when consumers of the cache should be able to complete current operation with the item from cache. You really need a synchronization here.
Most obvious you can do here, is to use ReaderWriteLockSlim
and a wrapper around regular Dictionary<TKey, TValue>
.
When someone wants to use item from cache, it acquires a read access. When someone wants to modify cache (add an item, or invalidate cache at all), it acquires a write access (hence, writer can't invalidate cache, until last reader won't release the lock).
Another option is to consider approach, when you're just catching ObjectDisposedException
. But this approach assumes, that currect operation can be interrupted from the outside.