OutputCache behavior in ASP.NET MVC 3

kidoman picture kidoman · Nov 23, 2010 · Viewed 13.6k times · Source

I was just testing Output Caching in the RC build of ASP.NET MVC 3.

Somehow, it is not honoring the VaryByParam property (or rather, I am not sure I understand what is going on):

public ActionResult View(UserViewCommand command) {

Here, UserViewCommand has a property called slug which is used to look up a User from the database.

This is my OutputCache declaration:

[HttpGet, OutputCache(Duration = 2000, VaryByParam = "None")]

However, when I try and hit the Action method using different 'slug' values (by manupulating the URL), instead of serving wrong data (which I am trying to force by design), it is instead invoking the action method.

So for example (in order of invocation)

/user/view/abc -> Invokes action method with slug = abc /user/view/abc -> Action method not invoked /user/view/xyz -> Invokes action method again with slug = xyz! Was it not supposed to come out of the cache because VaryByParam = none?

Also, what is the recommended way of OutputCaching in such a situation? (example above)

Answer

kidoman picture kidoman · Dec 11, 2010

Just wanted to add this information so that people searching are helped:

The OutputCache behavior has been changed to be 'as expected' in the latest release (ASP.NET MVC 3 RC 2):

http://weblogs.asp.net/scottgu/archive/2010/12/10/announcing-asp-net-mvc-3-release-candidate-2.aspx

Way to go ASP.NET MVC team (and Master Gu)! You all are awesome!