22

While I am working on cache, there is something like

VaryByParam

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

Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
Surya sasidhar
  • 29,607
  • 57
  • 139
  • 219
  • You can find an detailed explanation in the following link: http://stackoverflow.com/questions/3538012/how-do-i-use-varybyparam-with-multiple-parameters – Jonay Jul 11 '16 at 17:41

2 Answers2

43

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
Heinzi
  • 167,459
  • 57
  • 363
  • 519
22

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.

Rubens Farias
  • 57,174
  • 8
  • 131
  • 162