title: How to inspect cache policies inside System.Runtime.Caching.ObjectCache?
body: <p>I'm making use of the new .NET 4.0 Caching namespace: <code>System.Runtime.Caching</code>.</p>
  
  <p>Now, i'm just doing some prototype/fiddling with the new API, in order to work out the best fit for the real app.</p>
  
  <p>In line with that, i'm trying to create a page (ASP.NET MVC) that basically dumps out everything in the cache, particularly the following info:</p>
  
  <ul>
  <li>Cache Key</li>
  <li>Cache Object</li>
  <li>Cache Policy (expiry date, etc)</li>
  <li>Cache Dependencies (if any)</li>
  </ul>
  
  <p>However, i can't seem to get anything except the key/object.</p>
  
  <p>Here's the code i'm currently playing with:</p>
  
  <pre><code>public ActionResult Index()
  {
     var cache = MemoryCache.Default;
  
     // i can get the list of cache keys like this:
     var cacheKeys = cache.Select(kvp =&gt; kvp.Key).ToList();
  
     // i can also get a strongly-typed "CacheItem" like this:
     CacheItem item = cache.GetCacheItem("someKey");
  
  }
  </code></pre>
  
  <p>I would have hoped the "CacheItem" class would expose the information i require (expiry, dependencies, etc - at least as "getters").</p>
  
  <p>But it doesn't. All it has is properties for key, value and region name.</p>
  
  <p>How can i inspect the items in the cache and spit out the information i require?</p>
  
  <p>Is there a namespace/class i'm missing?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Looks like there is a <strong><a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.changemonitor.aspx">ChangeMonitor</a></strong> class, but again - this doesn't give expiration info, it just allows you to subscribe to events when cache items are removed.</p>
  
  <p>There <em>must</em> be a way to just grab the items in the cache, and when they expire.</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Don't know if this should be a seperate question, but also - i'm confused as to what lifetime i should give my ObjectCache. MSDN says it's not a singleton, and you can in fact create multiple ObjectCache instances. What does that mean though, i have to use a fully-locked singleton when accessing the ObjectCache instance?</p>