Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3938414
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:10:55+00:00 2026-05-20T00:10:55+00:00

I’m making use of the new .NET 4.0 Caching namespace: System.Runtime.Caching . Now, i’m

  • 0

I’m making use of the new .NET 4.0 Caching namespace: System.Runtime.Caching.

Now, i’m just doing some prototype/fiddling with the new API, in order to work out the best fit for the real app.

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:

  • Cache Key
  • Cache Object
  • Cache Policy (expiry date, etc)
  • Cache Dependencies (if any)

However, i can’t seem to get anything except the key/object.

Here’s the code i’m currently playing with:

public ActionResult Index()
{
   var cache = MemoryCache.Default;

   // i can get the list of cache keys like this:
   var cacheKeys = cache.Select(kvp => kvp.Key).ToList();

   // i can also get a strongly-typed "CacheItem" like this:
   CacheItem item = cache.GetCacheItem("someKey");

}

I would have hoped the “CacheItem” class would expose the information i require (expiry, dependencies, etc – at least as “getters”).

But it doesn’t. All it has is properties for key, value and region name.

How can i inspect the items in the cache and spit out the information i require?

Is there a namespace/class i’m missing?

EDIT

Looks like there is a ChangeMonitor class, but again – this doesn’t give expiration info, it just allows you to subscribe to events when cache items are removed.

There must be a way to just grab the items in the cache, and when they expire.

EDIT 2

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:10:56+00:00Added an answer on May 20, 2026 at 12:10 am

    It doesn’t look to me that there is a way to retrieve the CacheItemPolicy once it’s been added to the cache collection.

    The best way around this is can think of is to cache the policy object along with the item you want to cache but just appending “Policy” to the key name so that you can later retrieve the policy. This obviously assumes you have control over actually adding the item to the cache in the first place. Example below:

    public ActionResult Index()
        {
            string key = "Hello";
            string value = "World";
    
            var cache = MemoryCache.Default;
            CacheItemPolicy policy = new CacheItemPolicy();
            policy.AbsoluteExpiration = DateTime.Now.AddDays(1);
            cache.Add(new CacheItem(key, value), policy);
            cache.Add(new CacheItem(key + "Policy", policy), null);
    
            CacheItem item = cache.GetCacheItem(key);
            CacheItem policyItem = cache.GetCacheItem(key + "Policy");
            CacheItemPolicy policy2 = policyItem.Value as CacheItemPolicy;
    
            ViewBag.Message = key + " " + value;
    
            return View();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.