In my ASP.NET Web application, all the requests to pages access this common static cache class. (So it has to be thread safe)
Is it safe to refresh this cache by calling the Refresh method of Cache class as implemented below. Or it causes sync problems?
static class Cache
{
static Dictionary<string, string> cachedCodeNames;
static readonly object sync = new object();
public static string GetName(string code)
{
return CodeNames[code];
}
public static void Refresh()
{
cachedCodeNames = null;
}
static Dictionary<string, string> CodeNames
{
get
{
if (cachedCodeNames == null)
{
lock (sync)
{
if (cachedCodeNames == null)
{
cachedCodeNames = WebServiceManager.GetCodeNameCache();
}
}
}
return cachedCodeNames;
}
}
}
static class WebServiceManager
{
internal static Dictionary<string, string> GetCodeNameCache()
{
throw new NotImplementedException();
}
}