.NET/ASP.NET Interview Question - How to cache an ASP.NET page?

 Posted by ArticlesMaint on 4/13/2011 | Category: ASP.NET Interview questions | Views: 3992

Output Cache is used to Cache an ASP.NET page.

Output Cache is called as directives.

The below diagram shows, how exactly the caching is done.

                               Diagram of Caching.

Caching can be done in three ways as followings.

  1. Cache the complete page.
  2. Cache the portion of the page.
  3. Cache the complete page but a portion is static.

The below diagram will give an idea of Caching different forms.


                           Different types of Caching.

The below code snippet shows how to Cache the complete page.

<%@ OutputCache Duration="20" Location="Server"  VaryByParam="none" %> 

To Cache the portion of the page.we have to add web user control page and the directive is placed at the top of user control page.(.ascx file).

<%@ OutputCache Duration="20" VaryByControl="LiveScore" VaryByParam="*"%>

Now, for Caching the complete page but a portion should be static. we have to add web user control page and later you can define the output cache in the source of the web user control page.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response