I've taken a look at the other VaryByParam questions, but I haven't been able to find the answer to my question. I have an MVC site that has the following action defined:
[OutputCache(Duration = 30, VaryByParam = "TargetID")]
public JsonResult IsThingAllowed(int TargetID)
{
bool isAllowed = IsAllowed(TargetID);
return Json(isAllowed, JsonRequestBehavior.AllowGet);
}
No matter what comes in for TargetID, the cached value gets returned. However, if I change TargetID
to be *
, it works as expected (cached values vary by TargetID
):
[OutputCache(Duration = 30, VaryByParam = "*")]
Here's the AJAX call:
$.ajax({
url: "/MyController/IsThingAllowed",
type: "POST",
data: JSON.stringify({ "TargetID": id }), // This is definitely varying!
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data, textStatus, xhr) {
updateThing(data);
},
error: function (xhr, textStatus, error) {
}
});
What am I doing wrong when the parameter is explicitly named?
EDIT: Works if we use GET
instead of POST
.. but POST
obviously works, since it works when we use *
.
Here's it working with GET
:
$.ajax({
url: "/MyController/IsThingAllowed",
type: "GET",
data: { TargetID: id },
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data, textStatus, xhr) {
updateThing(data);
},
error: function (xhr, textStatus, error) {
}
});