尽管我指定了一个唯一键,但似乎以下代码将为 5 个请求返回一个值,然后为下一对返回另一个值,然后恢复为原始请求中保存的值并继续直到有 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);
很困惑,这是因为线程还是什么?