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:
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 asp.net cache store and What is the most efficient way to store / retrieve items in asp.net httpContext.Cache