I have a question about caching in ASP.NET MVC 5. I have an action that decorates with OutputCacheAttribute. something like this: OutputCache(Duration = 900, Location = Server, VaryByParam = "id")
somewhere in my application I want to manage caches and remove them. I used Response.RemoveOutputCacheItem(Url.Action("Index", "Home")) to remove all caches of an action, but it doesn't work.
The HttpResponse.RemoveOutputCacheItem() method was worked on actions with parameters but I want to clear all outputcaches of the action without parameters.
for example:
Controller:
[OutputCache(Duration = 900, VaryByParam = "*")]
public ActionResult About(int id)
{
return View();
}
Routing:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Remove by below code:
var x = Url.Action("About", "Home");
Response.RemoveOutputCacheItem(x);