This article mainly introduced the ASP.net outputcache detailed explanation, this article explained the OutputCache grammar, the OutputCache parameter, the OutputCache use example and so on the content, the need friend may refer to under
When a user accesses a page, the entire page is saved in memory by the server, which caches the page. When the user accesses the page again, the page does not perform data operations again, the page first checks to see if there is a cache in the server, and if the cache exists, gets the page information directly from the cache and creates the cache if the page does not exist.
Page output caching applies To pages that have more data than do too many events, and cannot use page output caching if a page needs to perform a large number of event updates, as well as data updates. The page output cache can be declared using the @outputcatch directive, as shown in the sample code.
The code is as follows:
<%@ OutputCache duration= "varybyparam=" "None"%>
The above code declares the page cache using the @outputcatch directive, which is cached for 120 seconds. The @OutputCatch directive includes 10 properties that allow you to cache settings for different scenarios of the page, and the common properties are as follows:
CacheProfile: Gets or sets the outputCacheProfile name.
Duration: Gets or sets the time that a cache entry needs to remain in the cache.
VaryByHeader: Gets or sets a well delimited set of HTTP header names that are used to change cache entries.
Location: Gets or sets a value that determines the location of the cached item, including any, Clint, downstream, None, server, and ServerAndClient. The default value is any.
VaryByControl: Gets or sets a cluster of delimited control identifiers that are contained within the current page or user control to change the current cache entry.
Nostore: Gets or sets a value that determines whether the "Http cache-control:no-store" directive is set.
VaryByCustom: Gets the list of custom strings that the output cache uses to change cache entries.
Enabled: Gets or sets a value that indicates whether output caching is enabled for the current content.
VaryByParam: Gets a list of query strings or form post parameters.
By setting the appropriate properties, you can set the appropriate cache for the page, and when you need to set the cached item for default.aspx, you can set it using the VaryByParam property, as shown in the sample code.
The code is as follows:
<%@ OutputCache duration= "varybyparam=" "None"%>
The code above uses the Duration property and the Varbyparam property to set the cache property of the current page. Overall caching settings for a page are often unnecessary and often confusing, such as default.aspx?id=1 and default.aspx?id=100 pages that might be present in the cache are the same, often not what developers want. You can specify caching parameters by configuring the Varbyparam property, as shown in the sample code.
The code is as follows:
<%@ OutputCache duration= "%>" varybyparam= "id"
The above code is cached by the parameter ID, and when the ID entry is different, the ASP. NET does not have the same page cache. This ensures that the pages displayed by Default.aspx?id=1 and default.aspx?id=100 are not consistent when cached. Varbyheader and Varbycustom are primarily used to customize the appearance or content of a page based on the client accessing the page. In ASP.net, a page may need to render output for PC users and mobile users, so different data can be cached by different versions of the client, as shown in the sample code.
The code is as follows:
<%@ OutputCache duration= "varybyparam=" "None" varybycustom= "Browser"%>
The preceding code sets a separate cache entry for each browser.