How can you cache Multiple Versions of a Page?

 Posted by Bhakti on 11/16/2009 | Category: C# Interview questions | Views: 3088

Using output cache you can cache multiple versions of the page.

We can either use,…
- @ OutputCache directive at design time declaratively for Declarative Approach
- Response.Cacheclass at runtime for Programmatic Approach.

With @ OutputCache directive four parameters of VaryByParam , VaryByControl, VaryByHeader, VaryByCustom allows user to cache page depending on query string, control value, request's HTTP header, request's HTTP header respectively.
For an example:

To turn off caching,
Declarative Approach:
<%@ OutputCache Location="None" VaryByParam="None" %>

Programmatic Approach:

To cache the output for each HTTP request that arrives with a different ID:
Declarative Approach:
<%@ OutputCache duration="60" varybyparam=" ID" %>

Programmatic Approach:

Response.Cache.VaryByParams["ID"] = true;

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response