I have a controller action which receives a Person
type parameter. The parameter is bound from a JSON request using the JSON based model binding feature.
My VaryByParam
is not working in this case, because the request doesn't hold any "classic" variables (eg. GET or POST), but the data is in the HTTP body in this case. On client-side I use KnockoutJS
so I post the data using ko.toJSON
method.
How could I achieve output caching based on a field's value in the JSON request?
The example is only for demonstration.
// model
public class Person {
public int PersonID { get; set; }
public string Name { get; set; }
}
// action
[OutputCaching(Duration = 60, VaryByParam = "PersonID")]
public JsonResult Process(Person person) {
...
}
// client-side
$.post({
url: '/mycontroller/myaction',
...
data: ko.toJSON(personViewModel),
...
});