简体   繁体   English

什么是asp.net中的VaryByParam?

[英]What is VaryByParam in asp.net?

While I am working on cache, there is something like 当我在缓存时,有类似的东西

VaryByParam 的VaryByParam

in page directive. 在页面指令中。 So what is this? 这是什么? Can anybody explain it to me? 任何人都可以向我解释一下吗?

To quote from the MSDN documentation : 引用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. 默认情况下,这些字符串对应于使用GET方法属性发送的查询字符串值,或使用POST方法发送的参数。 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. 可能的值包括none,星号(*)以及任何有效的查询字符串或POST参数名称。

So, if you set it to "A;B" , then these URLs will be cached separately: 因此,如果将其设置为"A;B" ,则这些URL将单独缓存:

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: 但这些URL将访问相同的缓存条目:

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

From @ OutputCache (MSDN) : 来自@ 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. 默认情况下,这些字符串对应于使用GET方法属性发送的查询字符串值,或使用POST方法发送的参数。 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. 可能的值包括none,*和任何有效的查询字符串或POST参数名称。

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. 通过使用它,如果使用相同的变量值调用页面,则将从缓存中检索该页面,并且在达到Duration参数中指定的Duration之前不会执行该页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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