我有一个线程运行在我的ASP.Net后面。在这个线程我把数据在这样的高速缓存:从其他线程访问HttpRuntime.Cache
HttpRuntime.Cache.Insert("test", "test", null, DateTime.Today.AddHours(6), Cache.NoSlidingExpiration);
在其他线程(网页),我第一次检查,如果缓存中包含的所有数据,然后尝试从缓存中获取对象,像这样:
if (HttpRuntime.Cache.Count > 0) {
var test = (string)HttpRuntime.Cache["test"];
}
编辑:当我试图做var test = (string)HttpRuntime.Cache["test"];
缓存将走空每次(或将要删除的对象,没有测试缓存多个对象),再加上var test
也为空。这是ofcourse当HttpRuntime.Cache.Count比0
哦更大,它使没有例外或任何
你能澄清你是说在你的if语句'Cache.Count> 0'中,但有时在'var test =(string)HttpRuntime.Cache [“test”];'它是空的? – 2012-07-24 15:59:55
每次当我试图做'var test =(string)HttpRuntime.Cache [“test”];'缓存将变空(或将删除对象,还没有测试过)加var test '也是空的。当'HttpRuntime.Cache.Count'大于0时,这是当然的 – 2012-07-24 16:57:59