私の ASP.NET Web アプリケーションでは、ページへのすべての要求がこの共通の静的キャッシュ クラスにアクセスします。(したがって、スレッドセーフでなければなりません)
以下に実装されている Cache クラスの Refresh メソッドを呼び出して、このキャッシュを更新しても安全ですか。それとも、同期の問題が発生しますか?
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();
}
}