一意のキーを指定しましたが、次のコードは 5 つのリクエストに対して 1 つの値を返し、次に次のカップルに対して別の値を返し、元のリクエストで保存された値に戻り、10 の異なるオブジェクトがすべて存在するまで続行します。同じキーで保存されます。これらの値のどれがキャッシュから返されるかは、ほぼランダムに見えます。
string strDateTime = string.Empty;
string cachename = "datetimeexample";
object cachedobject = HttpRuntime.Cache.Get(cachename);
if (cachedobject != null)
strDateTime = (string)cachedobject;
else
{
strDateTime = DateTime.Now.ToString();
HttpRuntime.Cache.Insert(cachename, strDateTime, null, DateTime.MaxValue, TimeSpan.FromDays(10), CacheItemPriority.NotRemovable, null);
}
Response.Write(strDateTime +" keys:"+ HttpRuntime.Cache.Count);
非常に混乱しています。これは、スレッド化または何かが原因ですか?