开发者

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

开发者 https://www.devze.com 2023-03-16 04:19 出处:网络
This question already has answers here: Clearing Page Cache in ASP.NET (8 answers) Closed 3 years ago. I want an easy way to clear cached pages on my asp.net-mvc website.
This question already has answers here: Clearing Page Cache in ASP.NET (8 answers) Closed 3 years ago.

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");
 }


For a MVC based solution you can do something like this

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号