Can someone please tell me if the following method is thread safe. Also, please assume the call to _cache.GetOrCreate(...) is thread-safe. This method is the ONLY place in the application that creates or updates the region (dictionary). The class containing this method is a singleton, so multiple threads will access it.
public IEnumerable<string> GetReportLookupItems<T>(string cacheKey, Func<IEnumerable<string>> factory)
{
Dictionary<string, IEnumerable<string>> region = _cache.GetOrCreate("Cache-Region:LookupItems", () => new Dictionary<string, IEnumerable<string>>());
IEnumerable<string> items;
if (!region.TryGetValue(cacheKey, out items))
{
region[cacheKey] = items = factory();
}
return items;
}