System.Runtime.Caching.MemoryCache奇怪的行为? [英] System.Runtime.Caching.MemoryCache strange behavior?

查看:384
本文介绍了System.Runtime.Caching.MemoryCache奇怪的行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有这个问题上的MSDN论坛太(<一href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/0a666d5e-9bda-47bd-8dd3-98d32eb5fe60/?prof=required" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/0a666d5e-9bda-47bd-8dd3-98d32eb5fe60/?prof=required),想我会得到乡亲在这里的观点:

Have this question up on the MSDN forums too (http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/0a666d5e-9bda-47bd-8dd3-98d32eb5fe60/?prof=required), thought I'd get an opinion of folks here :

下面是我的即时窗口中的输出:

Here's the output of my immediate window :

(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)

Under what conditions will adding to a MemoryCache return true, but an object will not be cached? (The call to GetCount and the one following it are made immediatley after adding to the cache)

推荐答案

进入这个情况的最简单的方法就是添加的MemoryCache 对象而处置被调用。您可以通过使用Visual Studio调试器看到的MemoryCache 对象的私有 _disposed 属性检查。将鼠标悬停在引用缓存变量,使用快速手表,或使用即时窗口。

The easiest way to get into this situation is to Add on a MemoryCache object for which Dispose has been called. You can check this by using the Visual Studio debugger to see the private _disposed property of the MemoryCache object. Hover over a variable that references the cache, use a quick watch, or use the immediate window.

这篇关于System.Runtime.Caching.MemoryCache奇怪的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆