ASP. NET page and control cache settings

Source: Internet
Author: User

@ Outputcache command:

<% @ Outputcache duration = "# ofseconds" location = "any | client | downstream | sever | none" shared = "True | false" varybycontrol = "controlname" varybycustom = "browser | customstring "varybyheader =" headers "varybyparam =" parametername "%>

Duration -- time in seconds
Location -- place of use (default any) (user control output cache is not supported)
Shared -- whether to share (false by default) (page output cache is not supported)
Varybycustom -- customize and modify the cache content browser, customstring -- override the getvarybycustomstring method in global. asax
Varybyheader -- modify the content in the cache area based on the HTTP header information (the user control output cache is not supported)
Varybyparam -- "NONE" -- do not change "*" -- all parameters change "parameter name; parameter name..." -- changes with the given Parameter
Varybycontrol -- changes with the control name (page output cache is not supported)

 

Example: <% @ outputcache duration = "60" varybyparam = "NONE" %>

 

Configure ApplicationProgramLevel cached in Web. config.

Add the following XML as a sub-item of the system. Web element:

<! -- Caching section group -->
<Caching>
<Outputcachesettings>
<Outputcacheprofiles>
<Add name = "appcache1" enabled = "true" Duration = "60"/>
</Outputcacheprofiles>
</Outputcachesettings>
</Caching>

 

Save the file and close it.

Open or switch to the page you just used, and then switch to the "Source" view.

Change the @ outputcache command to the following: <% @ outputcache cacheprofile = "appcache1" varybyparam = "NONE" %>

 

Use the @ outputcache command

Use the @ outputcache command to implement general requirements for page output cache. @ Outputcache command the header Declaration of the user control contained in the ASP. NET page or page. This method is very convenient. You only need a few simple attribute settings to implement the page output Cache Policy. @ Outputcache command DeclarationCodeAs follows.

@ Outputcache command code

<% @ Outputcache cacheprofile = "" nostore = "True | false" Duration = "# ofseconds" shared = "True | false" location = "any | client | downstream | Server | none | serverandclient "sqldependency =" database/table name pair | commandnotification "varybycontrol =" controlname "varybycustom =" browser | customstring "varybyheader =" headers "varybyparam =" parametername "%>

As shown above, the @ outputcache command contains 10 attributes, including cacheprofile, nostore, duration, shared, location, sqldependency, varybycontrol, varybycustom, varybyheader, and varybyparam. These attributes are used to set the cache time, cache item location, and SQL data cache dependency. The following describes the basic concepts of the above attributes.

Cacheprofile -- used to define the name of the cache settings associated with the page. Is an optional attribute. The default value is null (""). Note that the @ outputcache command in the user control does not support this attribute. When this attribute is specified on the page, the attribute value must match the name of an available item in the outputcacheprofiles element in the <outputcachesetfiles> Configuration section of the web. config file. If the name does not match the configuration file, an exception is thrown.

Nostore -- this attribute defines a Boolean value to determine whether to block level-2 storage of sensitive information. Note that the @ outputcache command in the user control does not support this attribute. Setting this attribute to true is equivalent to executing the code "response. cache. setnostore ();" during the request ();".

Duration -- used to set the cache time of a page or user control. The Unit is seconds. By setting this attribute, you can create an expiration Policy for the HTTP response from the object and automatically cache the page or user control output. Note that the duration attribute is required. Otherwise, the analyzer error may occur.

Shared -- this attribute defines a Boolean value to determine whether the output of a user control can be shared by multiple pages. The default value is false. Note that the @ outputcache Command included in the ASP. NET page does not support this attribute.

Location -- specifies the location of the output cache. Its Attribute values are outputcachelocation enumeration values, which are any, client, downstream, none, server, and serverandclient. The default value is any, indicating that the output cache can be used for all requests, including client browsers and proxies.ServerOr the server that processes the request. Note that the @ outputcache command in the user control does not support this attribute.

Sqldependency -- this attribute identifies the string value of a group of database/table name pairs. The output cache of pages or controls depends on these name pairs. Note: The sqlcachedependency class monitors the tables in the database on which the output cache depends. Therefore, when items in the table are updated, table-based round robin is used to remove these items from the cache. When the notification (in SQL Server 2005) is used with the commandnotification value, the sqldependency class is used to register the query notification with the SQL Server 2005 server. In addition, the commandnotification value of the sqldependency attribute is only valid on the ASP. NET page. The control can only use table-based round robin For the @ outputcache command.

Varybycontrol -- this attribute uses a semicolon-separated string list to change 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. This attribute is required in the @ outputcache command unless the varybyparam attribute is already included.

Varybycustom -- customize any text required by the output cache. If the property value is browser, the cache varies with the browser name and major version information. If you enter a custom string, you must re-write httpapplication. getvarybycustomstring in the global. asax file of the application.

Varybyheader -- this attribute contains the HTTP header list separated by semicolons, 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. The varybyheader attribute enables 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 -- this attribute defines a semicolon-separated string list 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. It is worth noting that this attribute is required when the 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 not, a analyzer error occurs. If you do not need to change the cache content with any specified parameter, you can set this value to "NONE ". If you want the output cache to change according to all parameter values, set the attribute to "*".

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.