Gautam Buddha Temple Varanasi,Varanasi - Buddhist Pilgrimage

Tuesday, January 21, 2014

Caching in ASP.NET ?

Caching is technique of persisting the data in memory for immediate access to requesting program calls.Caching is feature to improve application performance of web application.There are three types of caching available in

Output Caching :
This is at the page level and one of the easiest way of caching a page.
 <%@ OutputCache Duration="60" VaryByParam="none" %>  

VaryByParam attribute makes sure that there is a single cached page available for this duration specified.

Fragment Caching :
Some times we might want to cache just portions of a page.
Eg.Suppose we want to cache header of our page which will have the some content for all users.There might be some Text/Images in the header which might change everyday.In this case we will cache this header for a duration of a day. The solution will be put header in a user control and then cached the user control as output caching.As below
 <% OutputCache Duration="10" VaryByParam="None"%>  

This technique is known as fragment Cachng.

Data Caching :
ASP.NET also support caching of data as objects.We can store objects in memory and use then across various pages in our application.This feature is impemented using the cache class.The cache class has life time equivalent to that of the applicaton objects can be stored as name pairs in the cache.
 Cache["name"] ="santosh";  
 if(Cache["name"] != null)  
    lbl.text = Cache["name"].ToString();  

No comments:

Post a Comment