Can you force a delete of (page and partialView) OutputCache in asp.net-mvc [duplicate]
Asked Answered
C

1

6

I want an easy way to clear cached pages on my asp.net-mvc website.

I have expensive DB operations so i often use outputcaching to make the site run faster. I have 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 times (when things go wrong) when i want to explicitally clear this cache (regardless of the existing Cache duration)

is there anyway for full and partial page Outputcaching to remove the cached page and run through the full code ?

NOTE: I see that this question is asked already in general around asp.net like here but i dont see an asp.net-mvc specific solution

i have tried this but it doesn't seem to work:

 public ActionResult ClearCache()
 {
      this.HttpContext.Response.RemoveOutputCacheItem("/MyController/Index.aspx");
      this.HttpContext.Response.RemoveOutputCacheItem("/MyController/MyView.ascx");
 }
Cindacindee answered 27/6, 2011 at 17:37 Comment(0)
S
0

For a MVC based solution you can do something like this

this.HttpContext.Response.RemoveOutputCacheItem(Url.Action("MyAction","MyController",new{ id = 1234}));
Syphon answered 15/12, 2015 at 6:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.