Can you force delete (page and partialView) OutputCache in asp.net-mvc

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"); } 
+6
source share
2 answers

I think you will find your answer here: Clearing the page cache in ASP.NET

+1
source

For a MVC based solution, you can do something like this

 this.HttpContext.Response.RemoveOutputCacheItem(Url.Action("MyAction","MyController",new{ id = 1234})); 
0
source

Source: https://habr.com/ru/post/891477/


All Articles