Answer: Using output cache you can cache multiple versions of the page.
We can either use,…
- @ OutputCache directive at design time declaratively for Declarative Approach
OR
- 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:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
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.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.VaryByParams["ID"] = true;
Asked In: Many Interviews |
Alert Moderator