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}
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)
The easiest way to get into this situation is to
Add
on aMemoryCache
object for whichDispose
has been called. You can check this by using the Visual Studio debugger to see the private_disposed
property of theMemoryCache
object. Hover over a variable that references the cache, use a quick watch, or use the immediate window.