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.
- Cache the complete page.
- Cache the portion of the page.
- 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 |