Caching in ASP.NET

What is Caching?

Caching is a technique in web development for storing frequently used data in memory.

Once used the caching technique, the application performance becomes very fast.

For example, when the same data is required for the next time, it will be able to get the data from the caching itself, instead of the database or the application source.

Asp.net Caching

Primary Caching is of two types in asp.net

  1. Output caching
  2. Data caching

Output caching: This is one of the cache technique in asp.net. When a page wants to put in the cache, then the output caching is useful, for example, a webpage/html page have text, images and controls, so when you require to put such data in the cache, at that time the output caching proves to be useful.

Syntax: <%@ OutputCache Duration="60" VaryByParam="None" %>   

The above syntax is put on the page (.aspx) header block

Data caching: This is the second caching technique in the caching concept, the method of putting data set or data table data into caching, for example, once a client sends a request to get the data from the server means the data will be fetched from the database every time, means the database should be hit. To avoid the action, one should use the data caching technique.

Syntax: Cache [“CacheName”] =DatasetObject;

The above syntax is to make the data cache

To store Cache data syntax

DataSet DatasetObject =x.Storeprocedurename();
Cache["StudentDataSet"] = DatasetObject
GridView_Student.DataSource=(DataSet)Cache["StudentDataSet "];
GridView_Student.DataBind();
 

Conclusion

To improve the performance of the application, Caching technique will be useful.