Geeks With Blogs

News My Blog has been MOVED to
Michael Freidgeim's OLD Blog My Blog has been MOVED to

I have a reference data, loaded from database table in ASP.NET application.
I wanted to store some of the records in the cache, but only those that were called by some user, not the whole table.
I considered to options:

1. to store individual items directly in the HttpRuntime.Cache dictionary with some composite string  key(e.g. "MyTableName:"+ Row.Key.ToString()).

2. create new Dictionary<KeyType,TableRowType>(), and add the loaded records to the Dictionary. The dictionary itself should be added to HttpRuntime.Cache as one item.
The second way  allowed to group related items together and have TypeSafe classes 

I've read a few related links:

Improve the performance of your app with ASP.NET caching

My conclusion is to use  HttpRuntime.Cache directly with multiple items. It is a proven infrustructure to add/modify items and ASP.NET will be smart enough to remove from cache individual items that were not used for some time.

I still want to review Enterprise Library caching block to check if it has any essential benefits for ASP.NET compare to standard HttpRuntime.Cache.

Update 2012: I've re-checked this question again and found more confirmations to use standard cache instead of proprietorial dictionary implementation -see Efficiency of persistence methods for large cache store and What is the most efficient way to store / retrieve items in httpContext.Cache

However a new from ASP.Net 4 NET 4.0’s ObjectCache / MemoryCache should be considered. For benefits see Method Three: in Four Methods Of Simple Caching In .NET 

Posted on Wednesday, October 3, 2007 10:29 AM ASP.NET | Back to top

Comments on this post: To cache in individual items or one dictionary ?

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Michael Freidgeim | Powered by: