// Update based on comment
The cache is unique per app domain, so you don't need to worry. See MSDN here
There is one instance of the Cache
class per application domain. As a
result, the Cache object that is
returned by the Cache property is the
Cache object for all requests in the
application domain.
// 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.
private static readonly object lockme = new object();
public void SetDictionaryValue(string key, string value)
{
lock (lockme)
{
var lookup = (Dictionary<string, string>)GetFromCache("LookupDictionary");
lookup["key"] = value;
}
}
public string GetDictionaryValue(string key)
{
lock (lockme)
{
var lookup = (Dictionary<string, string>)GetFromCache("LookupDictionary");
return lookup["key"];
}
}
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?