While I am working on cache, there is something like
VaryByParam
in page directive. So what is this? Can anybody explain it to me?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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
Method 2
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0