Caching Application Block Released

News if you haven't heard, another application block has been released (actually a couple):

Caching Application Block (the other one is Aggregation)

I've read over the docs for the Caching block and at first glance it looks like it doesn't offer anything to ASP.NET developers that the built-in Cache API doesn't have, unless you're looking to store your cached data in a database (and suffer big perf penalties).

It's missing features that the intrinsic Cache object supports, such as providing access to the just-expired object in a CacheItemRemovedCallback (the app block only passes in the key, not the value), and it doesn't go further with than the intrinsic Cache object where the Cache object falls short (for instance, CacheItemRemovedCallback would be 1000 times more useful if it were guaranteed to complete execution BEFORE the item was actually removed from the cache.  The app block might have implemented this but it doesn't appear to have).

In short, this looks like an AWESOME addition to the .NET framework for non-web developers, but it doesn't look like anything ASP.NET developers are going to be anything but underwhelmed by.  By all means, tell me if I'm wrong - caching is of particular interest to me and I'd love to hear that this app block will give me things the intrinsic Cache object cannot.  And perhaps, some day, when I have time, I might extend the app block to have it handle database table cache dependencies or ItemExpiredButNotYetRemovedCallbacks.  But probably not; I'll just hope to see those in a future version of ASP.NET.

[Listening To: Redshift - Infamy]

8 Comments

  • BTW, you can use the Asp.Net cache from normal C# code. Just do this:





    Cache cache = HttpRuntime.Cache;


  • What's in the Cache that makes it part of HttpRuntime? I mean it should have been a generic object, shouldn't it be?

  • Keith - yes, I know, but good point. This framework could still be useful if you wanted more granular control of how caching works, I suppose (whether using ASP.NET or not).





    Faisal - I agree, Cache probably should have been a generic (System.Caching) namespaced object rather than a web-specific one from day one, but since Rob Howard and the ASP.NET team wrote it, they put it in "their" area...





    Steve

  • Keith - another question - does that work if ASP.NET is not installed, like on NT4 or if IIS isn't there, like on XP Home?


  • Keith - I tested HttpRuntime.Cache from a C# console application like you said but let me surprise you by saying that each call to *any* method of Cache object takes on average 20 ms. So I think it is not appropriate to use HttpRuntime.Cache from non-ASP.NET applications at this time.





    While within an ASP.NET application it only takes about 120 - 500 cycles (about 0.01 ms), so it is very fast within ASP.NET as expected.





    You can test it yourself. I used high performance QueryPerformanceCounter() so the time I get is accurate to the last microsecond.

  • A question does anyboby know if i use th Caching Application Block and pass a weekreferance object to the cache. will it be cleared on memory pressure?

  • All things come to those who wait.

    -----------------------------------

  • -----------------------------------------------------------
    amazing things thanx

Comments have been disabled for this content.