Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is VaryByParam in asp.net?

Tags:

c#

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?

like image 804
Surya sasidhar Avatar asked Dec 14 '09 08:12

Surya sasidhar


2 Answers

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 
like image 135
Heinzi Avatar answered Oct 16 '22 14:10

Heinzi


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.

like image 30
Rubens Farias Avatar answered Oct 16 '22 12:10

Rubens Farias