System.Runtime.Caching.MemoryCache奇怪的行为?

时间:2011-07-20 19:50:43

标签: .net caching

在MSDN论坛上也提出了这个问题(http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/0a666d5e-9bda-47bd-8dd3-98d32eb5fe60/?prof=required),我以为我会在这里得到一些人的意见:

这是我的即时窗口的输出:

(EmployeeCache as MemoryCache).Add("test", new Object(),DateTimeOffset.Now.AddMinutes(10));
true
(EmployeeCache as  MemoryCache).GetCount()
0
(EmployeeCache as  MemoryCache)
{<namespace>.CustomCache}
[<namespace>.CustomCache]: {[<namespace>.CustomCache}
base {System.Runtime.Caching.ObjectCache}: {<namespace>.CustomCache}
CacheMemoryLimit: 1887436800
DefaultCacheCapabilities: InMemoryProvider | CacheEntryChangeMonitors | AbsoluteExpirations |   SlidingExpirations | CacheEntryUpdateCallback | CacheEntryRemovedCallback
Name: "keyname"
PhysicalMemoryLimit: 99
PollingInterval: {00:02:00}

在什么条件下添加到MemoryCache会返回true,但是对象不会被缓存? (在添加到缓存后,对GetCount的调用及其后面的调用是immediatley)

1 个答案:

答案 0 :(得分:0)

遇到这种情况的最简单方法是在Add对象上MemoryCache调用Dispose。您可以使用Visual Studio调试器来查看_disposed对象的私有MemoryCache属性。将鼠标悬停在引用缓存的变量上,使用快速监视或使用即时窗口。