There are 2 ways to do caching in asp.net.
1. Output Caching
2. Data Caching
1. Output Caching : Ability of ASP.NET to cache entire output from a asp.net webpage.
Implementation of output cache –
Add following line below the page directive
It generate page once, then other all subsequent requests in certain time frame, when user requests page dont run it through asp.net just return the HTML that was generated on the previous run.
IF VaryByparameter =”CategoryId” THEN
ASP.NET cache page depends on categoryId, when a userrequest a page with the same categoryId in query string then the cached version of page will be displayed.
If another user request the same page with another categoryId then asp.net generates page again.
For 2 query string Parameters – VaryByParam=”ProductId;Quantity”
Substitution Control – When only one part of page need to regenerate every time, use substitution control.
Substitution control defines an area it always be requested on every round trip regardlessly whether page is cached or not.
2. Data Caching : Write code to programmatically cache an object (e.g. Dataset ,variable). So, in order to reduce the workload and time for data retrieving, you can use a caching functionality.
If(Cache[ObjectName] != Null)
-If ds is already cached means(not null) then it shows cached version of ds.
-If ds is not cached in Cache[ObjectName] array then ds binding method called.
As you can see, the usage of the caching functionality is quite simple. And, you can use any appropriate code in your application architecture inside the anonymous method so that it would be easy to add caching support to your application.