【问题标题】:System.Runtime.Caching.MemoryCache strange behavior?System.Runtime.Caching.MemoryCache 奇怪的行为?
【发布时间】:2011-12-24 08:53:02
【问题描述】:

在 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 的调用及其后的调用是在添加到缓存后立即进行的)

【问题讨论】:

    标签: .net caching


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-08
      • 2015-07-20
      • 2010-10-03
      • 2021-07-12
      • 2013-10-04
      • 2019-01-23
      相关资源
      最近更新 更多