简体   繁体   中英

What is VaryByParam in asp.net?

While I am working on cache, there is something like

VaryByParam

in page directive. So what is this? Can anybody explain it to me?

To quote from the MSDN documentation :

A semicolon-separated list of strings used to vary the output cache. By default, these strings correspond to a query string value sent with GET method attributes, or a parameter sent using the POST method. When this attribute is set to multiple parameters, the output cache contains a different version of the requested document for each combination of specified parameters. Possible values include none, an asterisk (*), and any valid query string or POST parameter name.

So, if you set it to "A;B" , then these URLs will be cached separately:

http://example.com/yourpage.aspx?A=1&B=4
http://example.com/yourpage.aspx?A=1&B=3
http://example.com/yourpage.aspx?A=2&B=3

but those URLs will access the same cache entry:

http://example.com/yourpage.aspx?A=1&C=4
http://example.com/yourpage.aspx?A=1&C=3

From @ OutputCache (MSDN) :

A semicolon-separated list of strings used to vary the output cache. By default, these strings correspond to a query string value sent with GET method attributes, or a parameter sent using the POST method. When this attribute is set to multiple parameters, the output cache contains a different version of the requested document for each specified parameter. Possible values include none, *, and any valid query string or POST parameter name.

By using it, if you call your page using same variable value, that page will be retrieved from your cache and will not be executed until time especified in Duration argument be reached.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM