I’m testing the ASP.NET MVC 3 OutputCache attribute and the behavior is as follows:
- If you don’t specify a VaryByParam attribute, it will automatically vary by all parameters
- If you specify, it will vary just by those separated by comma like “param1,param2”
But if your Action has a complex parameter, let’s say, a Person, I can’t make it to vary by a property of Person. Let’s say.. Person.Name
I can’t make it to work neighter by saying nothing or explicitly specifying model.Name
Is there a way I can do that?
You can either hack the API a bit by sending
Person.Nameas an additional parameter (just for the sake of caching), or you can useVaryByCustomattribute option and provide your own resolver. In the second case, you need to edit yourGlobal.asaxand override theGetVaryByCustomStringmethod:Then add
VaryByCustom="Person"to your attribute declaration.