我有一个存储使用60分钟的客户列表HttpRuntime.Cache WCF服务System.Web.Cache和HttpRuntime.Cache内存位置
如果您运行下面为什么字符串包含在“STRING3”第三次
string mykey = "mykey-1";
List<string> strings = null;
strings = HttpRuntime.Cache[mykey] as List<string>;
if (strings == null)
{
strings = new List<string>();
strings.Add("string1");
strings.Add("string2");
HttpRuntime.Cache[mykey] = strings;
}
else
{
strings.Add("string3");
}
我期望:
第1次轮:字符串对象为空,因此创建了“字符串1”和“字符串2”且将其缓存
第二牛逼ime round:将字符串拉出缓存,并添加'string3'
第3轮:将字符串拉出缓存,但在再次添加'string3'之前,它已经获得了它。
它是共享内存还是应用程序池中的东西。如果你把它从缓存中取出,然后改变它,它会改变缓存的版本,而不必重新添加它。
如果我提前
它应该像你期望的一样。它没有的原因不在于这个问题...你如何测试这个代码?在循环中运行3次? – usr 2013-03-22 12:22:42
不,我已将它复制到干净的网站并将其放入网页加载中。并打F5 3次 – user1829226 2013-03-22 12:54:06