I've got this action in MVC
[OutputCache(Duration = 1200, VaryByParam = "*")]
public ActionResult FilterArea( string listType, List<int> designersID, int currPage = 1 )
{
// Code removed
}
that fails to present the correct HTML with url like
- http://example.com/en-US/women/clothing?designersID=158
- http://example.com/en-US/women/clothing?designersID=158&designersID=13
Is this a know bug of OutputCache in .NET cause cannot recognize VaryByParam with a list param or am I missing something?
I too had the same issue in MVC3 and I believe it's still the same case in MVC5.
Here is the setup I had.
Request
POST, Content-Type:application/json, passing in an array of string as the parameter
Controller Method
I tried every option possible with OutputCache and it just wasn't caching for me. Binding worked fine for the actual method to work. My biggest suspicion was that OutputCache wasn't creating unique cache keys so I even pulled its code out of
System.Web.MVC.OutputCache
to verify. I've verified that it properly builds unique keys even when aList<string>
is passed in. Something else is buggy in there but wasn't worth spending more effort.Workaround
I ended up creating my own OutputCache attribute following another SO post. Much easier to use and I can go enjoy the rest of the day.
Controller Method
Custom Request class
I've inherited from
List<string>
so I can call the overriden.ToString()
method in MyOutputcache class to give me a unique cache key string. This approach alone has resolved similar issues for others but not for me.Custom OutputCache class