In MVC 3 I was outputcaching a JsonResult like this:
[OutputCache(Location = OutputCacheLocation.Server, Duration = 21600, VaryByParam = "None", VaryByCustom = "tenant")]
public JsonResult NotifyTasks(int id) {
return Json(new {pending = 5}, JsonRequestBehavior.AllowGet);
}
}
The URL to get the JSON was:
http://localhost/foo/notifytasks/1
At times I invalidate the cache pages with a simple
HttpResponse.RemoveOutputCacheItem("foo/notifytasks");
The method signature has changed and RemoveOutputCacheItem no longer works. The URL now has the querystring ?status=Status1 appended and this broke RemoveOutputCacheItem.
[OutputCache(Location = OutputCacheLocation.Server, Duration = 21600, VaryByParam = "None", VaryByCustom = "tenant")]
public JsonResult NotifyTasks(int id, string status) {
return Json(new {pending = 5}, JsonRequestBehavior.AllowGet);
}
http://localhost/foo/notifytasks/1?status=Status1
How do I get RemoveOutputCacheItem to work with an appended querystring?
I had the same problem, I think it comes down to that RemoveOutputCacheItem only accepts a path and a querystring is not part of the path (path <> url ?).
If you would register a seperate route
routes.MapRoute(
"DifferentRoute",
"{controller}/{action}/{id}/{status}",
new { controller = "Information", action = "Index", id = UrlParameter.Optional, status = UrlParameter.Optional }
);
then HttpResponse.RemoveOutputCacheItem("foo/notifytasks/1/Status1"); works fine.
I hope this is what you wanted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With