Usage of ASP + Page cache outputcache duration

Source: Internet
Author: User
Tags form post
The declared method controls the output cache policies of user controls contained in ASP. NET pages or pages. For more information about the output cache, see ASP. NET cache.

<% @ Outputcache duration = "# ofseconds" location = "any | client | downstream | Server | none" shared = "True | false" varybycontrol = "controlname" varybycustom = "browser | customstring "varybyheader =" headers "varybyparam =" parametername "%>
Attribute
Duration
Page or user control cache time (in seconds ). Set this attribute on the page or user control to create an expiration Policy for the HTTP response from the object and automatically cache the page or user control output.
Note that this attribute is required. If this attribute is not included, a analyzer error occurs.
Location
One of the outputcachelocation enumerated values. The default value is any.
The @ outputcache instruction in the user control (. ascx file) does not support this attribute.
Shared
A boolean value to determine whether the output of the user control can be shared by multiple pages. The default value is false. For more information, see the remarks section.
Note that the @ outputcache instruction in the ASP. NET page (. aspx file) does not support this attribute.
Varybycustom
Indicates any text required by the custom output cache. If the value assigned to this attribute is browser, the cache varies with the browser name and major version information. If you enter a custom string, you must Program In the global. asax file of, rewrite httpapplication. getvarybycustomstring method.
Varybyheader
A semicolon-separated HTTP header list used to change the output cache. When this attribute is set to multiple headers, the output cache contains different versions of a request document for each specified header.
Note: Set the varybyheader attribute to enable cache items in all HTTP 1.1 caches, not limited to ASP. NET caches. The @ outputcache command in the user control does not support this attribute.
Varybyparam
A semicolon-separated string list used to change the output cache. By default, these strings correspond to the query string values sent using the get method attribute, or to parameters sent using the POST method. When this attribute is set to multiple parameters, the output cache contains different versions of the Request Document for each specified parameter. Possible values include none, *, and any valid query string or post parameter names.
Warning this attribute is required when an ASP. NET page is cached. It is also required for user controls, unless the varybycontrol attribute is included in the @ outputcache command of the user control. If it is not included, an analyzer error occurs. If you do not want the cached content to change with any specified parameter, set this value to none. If you want the output cache to change according to all parameter values, set the attribute *.
Varybycontrol
A semicolon-separated string list to modify the output cache of the user control. These strings represent the ID attribute values of the ASP. NET Server Control declared in the user control. For more information, see some sections on the cache ASP. NET page.
Note that this attribute is required in the user control @ outputcache command unless the varybyparam attribute is already included. The @ outputcache command on the ASP. NET page does not support this attribute.
Remarks
The setting value for the page output cache is the same as that for httpcachepolicy. setexpires and httpcachepolicy. setcacheability operations through the httpresponse. cache attribute. If you set the varybyparam attribute when creating a user control, you can implement partial page cache of the control.

If the web form page requires the user to view the authorization, the output cache sets the cache-control HTTP header to private. For more information about all these topics, see the cache ASP. NET page.

If the shared attribute is set to true, the cached user control output can be accessed by multiple web forms pages. If it is not set to true, the default behavior is to cache a version output by the user control on every page that contains the user control. Enabling the shared attribute can potentially save a lot of memory. For more information, see some sections on the cache ASP. NET page.

Example
The following example shows how to set the duration of page or user control output cache.

<% @ Outputcache duration = "100" varybyparam = "NONE" %>
The next example shows how to instruct the output cache to cache pages or user controls. This cache is performed based on the position of the form post or query string and the counting form parameter. Each received HTTP request with different locations or counting parameters (or both) is cached for 10 seconds. Any subsequent request with the same parameter value will be satisfied from the cache until the input cache period expires.

<% @ Outputcache duration = "100" varybyparam = "location; count" %>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.