I need an easy way to clear cached pages on my asp.net-mvc website.
I have expensive database operations, so I often use outputcaching to make the site faster. I have a code that looks like this:
[OutputCache(Duration = 30000)] public ActionResult Index() { return View(); } [OutputCache(Duration = 30000, VaryByParam = "*")] public ActionResult GetData(MyParams myParams) { return PartialView("MyView", GetVM(myParams)); }
There are certain points (when things go wrong) when I want to explicitly clear this cache (regardless of the existing cache duration)
In any case, for a full and partial Outputcaching page, can you delete the cached page and execute the full code?
NOTE. . I see that this question has already been asked as a whole around asp.net, for example here , but I do not see asp.net -mvc specific solution
I tried this, but it does not work:
public ActionResult ClearCache() { this.HttpContext.Response.RemoveOutputCacheItem("/MyController/Index.aspx"); this.HttpContext.Response.RemoveOutputCacheItem("/MyController/MyView.ascx"); }
leora source share