1. Output Caching
With output caching, the final rendered HTML of the page is cached. when the same page is requested again, the control objects are not created, the page life cycle doesn't start, and none of your code executes. instead, the cached HTML is served.
You can cache an ASP. NET page in two ways. the most common approach is to insert the OutputCache directive at the top of your. aspx file, just below the Page directive, as shown here:
<%@ OutputCache Duration= VaryByParam= %>
The Duration attribute instructs ASP. NET to cache the page for 20 seconds.
The OutputCache command is actually asp.net that outputs three response headers to the response header:
VaryByParam = %>
Now when you request the page with additional query string information, ASP. NET will examine the query string. if the string matches a previous request and a cached copy of that page exists, it will be reused. otherwise, a new copy of the p age will be created and cached separately.
2. Caching with Specific Query String Parameters
Setting VaryByParam to the wildcard asterisk (*) is unnecessarily vague. It's usually better to specifically identify an important query string variable by name. Here's an example:
<%@ OutputCache Duration= VaryByParam= %>
In this case, ASP. NET will examine the query string, looking for the ProductID parameter. Requests with different ProductID parameters will be cached separately, but all other parameters will be ignored.
You can specify several parameters as long as you separate them with semicolons:
<%@ OutputCache Duration= VaryByParam= %>
In this case, ASP. NET will cache separate versions, provided the query string differs by ProductID or CurrencyType.