Theory/implementation question relating to caching

Topics: Caching Application Block
Oct 26, 2009 at 2:36 PM
Edited Oct 26, 2009 at 2:38 PM

I have recently been tasked with updating a web application that has become a little overwhelming to manage. I intend to start from scratch using some of the guidelines and code I have found relating to P&P from Microsoft.

I have a question relating to caching and was looking for advice as to the best approach;

Currently the application has various methods to retrieve a list of items. These methods use various store procedures in the database, via the Data Layer to select the appropriate records. These are then returned back to the UI. There is no caching at this moment, so every request for a list goes via this method.

I was thinking of changing this to something like the following and wondered if anyone had any thoughts or comments about this suggested implementation.


There are 2 methods with the business logic.

GetItems(int uid);
GetItemsByCategory(int uid, int categoryid);

GetItems() will check the cache for the existent of IList<item> with corresponing uid. If List does not exist in cache, retrieve using Data Layer and add to the cache.

When a call to GetItemsByCategory occurs, it will firstly get the IList<item> from GetItems() and then filter this using LINQ and then return the filtered results.

Now, from a code management point of view, and from my limited experience, I think this is a good approach. There is a single method to actually get the core data and other methods that use that to then filter based on the requirements of the UI. It also means that I do not have to write stored procedures either seperately or a single SP that can be parameterised.

The other option is to leave the code pretty much as is and return the IList<item> from various methods, which call seperate stored procedure based on what the UI is requesting (ItemsByCategory, ItemsByStatus, etc);

My question is this really, what is the best approach to take? Am I overcomplicating things and using caching for the sake of caching in this way? Am I potentially introducting a resource issue on the webserver while reducing the load on the DBserver?


Oct 27, 2009 at 9:09 AM


For the first said approach, the down side that I can see here is that it will consume much memory. I will allocate memory resources for data that later might not be used (after performing your filter methods). Personally, I would suggest that you would go for the approach #2 then add caching. Creating the separate stored procedure for each methods is worth the added performance.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.