In order to synchronise access to a Dictionary object in the ASP.NET cache, it is recommended that a synchroniser object be used.
Dino Esposito recommends a static variable as the target for locking (See http://www.drdobbs.com/cpp/184406369). However, this will only work if the ASP.NET Cache values have the same scope (or narrower scope) than static variables.
Does anyone know of documentation to this effect?
// Update based on comment
The cache is unique per app domain, so you don’t need to worry. See MSDN here
// Original answer
I’m not sure I quite understand your question. Anything in the cache is globally accessible (or at least accessible by anything that has access to the cache object).
This code would be safe as long as it is the only place you access the object.
But yes, it’s not guaranteed to be safe as there could be other code that retrieves the dictionary from the cache somewhere else and modifies it. Not sure how you could guarantee that that couldn’t happen. I mean you could use a GUID as a key, but you can iterate over all the cache variables anyway.
I’m not sure if I’m helping you here?