I encountered the above error message after applying the OutputCache attribute on ActionResult methods with no input parameters - why would I use VaryByParams in this case? Is this a bug in ASP.Net MVC or is there a way of using OutputCache without setting this property?
My big question is, if I have to use VaryByParams, what should I enter for a value if I have no parameters to cache against?
The output cache enables you to cache the content returned by a controller action. That way, the same content does not need to be generated each and every time the same controller action is invoked. Imagine, for example, that your ASP.NET MVC application displays a list of database records in a view named Index.
The OutputCache Attribute in ASP.NET MVC Application is used to cache the content returned by a controller action method for a specific time period, so that, if the subsequent request comes within that time period, then the content is going to be returned from the cache memory.
By default, when you use the [OutputCache] attribute, content is cached in three locations: the web server, any proxy servers, and the web browser. You can control exactly where content is cached by modifying the Location property of the [OutputCache] attribute. By default, the Location property has the value Any.
The output cache is located on the Web server where the request was processed. This value corresponds to the Server enumeration value. The output cache can be stored only at the origin server or at the requesting client. Proxy servers are not allowed to cache the response.
I never found a satisfactory answer for this - basically, you just need to add the VaryByParams property and if you don't have any parameters set it to the magic string "none".
http://msdn.microsoft.com/en-us/library/system.web.ui.outputcacheparameters.varybyparam.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With