Last post Aug 21, 2011 09:14 AM by ponki.d.monkey
Aug 18, 2011 11:45 PM|ponki.d.monkey|LINK
I have a question about caching in ASP.NET. I'm just not entirely sure if this question can be answered by output caching or other caching techniques that developers use these days. Here's the scenario:
For example, I have an e-Commerce site and my e-Commerce site has a "Featured Products" page which displays a list of all featured products. Let's say this list does not change frequently and let's say all users including anonymous/unauthenticated users
can access this page. So, you can just image how often people will be accessing this page.
1. Is this a good scenario to cache the list of "Featured Products" once this list has been retrieved from the database?
2. So, what happens if a user wants to sort the list by name (let's say there is a sort functionality)? Should the ASP.NET application sort the list from the cache instead of retrieving a sorted list from the database?
3. My biggest question is what if the e-Commerce site administrator changes a property value of one of the products that's included on the "Featured Products" page (let's say the price)? How will that product gets refreshed from the point of view of the
user viewing the "Featured Products" page?
Thank you all in advance!
Aug 19, 2011 12:16 AM|Bryan Strader|LINK
I think using cache for the featured items is a good idea, as it will be commonly loaded when a users first requests a page. You can set an expiration for the cache, so if you want to update your prices every couple hours, you could have the cache expire
every hour or so.
Aug 20, 2011 12:09 AM|ponki.d.monkey|LINK
Thanks for your response, Bryan. Do you happen to know any good caching C# library available? Or is the built in caching mechanism of ASP.NET good enough? Right now, I'm not really sure why I would need to use another caching mechanism aside from the one
that ASP.NET offers lol, but it might come in handy in the future.
Aug 20, 2011 08:21 AM|msdnphani|LINK
1) yes u can Cache the "Featured Products" as u say it changes very frequently .. if u know the approximate time in which it changes, u can set the
Duration tag in @OutputCache accordingly ...
2)if this sorted list is applicable in all the pages, better sort the list and place in Cahce .. if sorting is required in only 1 page , then get item from cache and Sort it and remember do not put the updated list in Cache again ...
3)for this u need to set the Cache Depedency ... if the value, is changed in SQL DATABASE, u can use SqlCacheDependency class or u can use simple CacheDepedency and specify the file changed ..
Cache Dependency:if an item is set into Cache specifying its Cache depedency,the item in Cache gets cleared if the Cache Depedency item changes ..
Aug 21, 2011 09:14 AM|ponki.d.monkey|LINK
Great! Thanks a lot, Siva. That's the answer I'm looking for. ~Cheers!