HttpRuntime.Cache Management

I recently started publishing articles with AspAlliance.  The first one was A New Approach to HttpRuntime.Cache Management. It's been a topic that I have done quite a bit of work on and I felt that certain aspects were going unnoticed. I hope you enjoy reading it as much as I had writing it.

Trackbacks

  • CodeStock 2009!
    Posted on 6.27.2009 at 3:52 PM

    I was invited to speak at CodeStock 2009 this year. There were some great people here, met some new people I've only previously known on Twitter. I wasn't able to be here for most of the Friday sessions, but did go to one on Friday afternoon and several

  • CodeStock 2009!
    Posted on 6.27.2009 at 4:13 PM

    I was invited to speak at CodeStock 2009 this year. There were some great people here, met some new people

7 Comments

  1. Sasha Says:

    Nice concept, I saw it in the Community Server and we use similar locking approach in our product. We do not use delegates for refreshing the cache though, just to get rid of the locks stored in the collection. That said, I do have a question, when using delegates for refreshing cache, don't you end up with a lot of unused cached values and refresh overhead (calls to delegates when cache is expired)? Or is there method that removes those cache entries at some point?

    Thanks!

  2. David L. Penton Says:

    Sasha,

    I did simplify the examples in my article somewhat. The refresh of the cached values only occurs when there was more than one external access to retrieve data. So, the data doesn't live indefinitely refreshed. There are other alternatives to this, such as being based on age of the data item. Quite frankly, I think either is a reasonable alternative.

    Thanks,

    David

  3. Sasha Says:

    Oh yeah, I forgot about the age. I wish I found an article a little earlier. Kinda implemented similar pattern for locking cache entries to prevent double writing/reading in high load sites.

    Does repopulating cache in ItemRemovedCallback offer any significant performance improvements as supposed to using locking and reloading data inside the calling function? Seems like it will be harder to diagnose issues (if any) since that happens in a background thread. Also what about maintainability? Seem like it requires developers to be familiar with limitations of multi threaded environement (which most asp.net developers are not really aware :) ) and delegates.

    Thanks for responding and great article btw!

  4. David L. Penton Says:

    Sasha,

    There is an error delegate that can be set as well, so that any errors can be tracked.

    Thanks,

    David

  5. Curt Drake Says:

    David,

    I liked what I saw in your article "A New Approach to HttpRuntime.Cache Management". I downloaded the code, but there is not any documentation for the methods and properties of these classes. That would not be a problem, but it does not appear that there is any internal documentation in these classes either. Do you have any documentation for these classes anywhere? If you do not have any documentation maybe you could help illustrate how to do the following (I will be caching a generic list):

    1) Populate a cache object for the first time

    2) Retrieve an object from the cache

    3) Manually update or replace a cache object

    4) Refresh the cache on a specified time interval or at a certain time each day

    Thanks,

    Curt


Leave a Reply