This post describes details about OuputCache
Caching : caching is mechanism in which you can store information on client side or server side or both for specified amout of time,can be understand by example that suppose you go to shop to purchase shirt now you try different different shirts and from which you only purchase one or two and checkout from shop.Nowshopkeeper has two options with shirts either he can put them back to their location or put them on customers desk from where they can choose again.benifit of the second option is that shopkeeper need not to go to take shirts which customers like and hence shopkeeper roundtrip time reduces.The disadvantage is that if shopkeeper not put all those shirts back after a specifed amount of time then there would be burden on customer desk .Same happends with cache if you store information in cache for specified amount of time then there would be benifit that you don't need to pick the relative information again and again and hence your application's performance increases.
To use output caching in asp.net mvc use OutputCache attribute as show below with specified parameters
VaryByParams : suppose you have two pages one displays the Category and other displays its details.Now you if cache both of the pages with VaryByParams as "None",Even you click on any of the category you will see the exact same content as previous one but if you specify VaryByParams then your detail page will cache the different different selected category not that one which is being clicked first.
Location: specify the location for caching either on server side or client side or both.
As you can see i have added the Duration for 10 secs so the page will cached for 10 secs.
Note: asp.net mvc it is recommended to use this before respective action as OutputCache directive seems to bleeding over web forms.












0 comments:
Post a Comment