你能否强制删除asp.net-mvc中的(page和partialView)OutputCache

leo*_*ora 6 c# asp.net-mvc outputcache output-caching

我想要一个简单的方法来清除我的asp.net-mvc网站上的缓存页面.

我有昂贵的数据库操作,所以我经常使用输出缓存来使网站运行得更快.我的代码看起来像这样:

    [OutputCache(Duration = 30000)]
    public ActionResult Index()
    {
         return View();
    }

    [OutputCache(Duration = 30000, VaryByParam = "*")]
    public ActionResult GetData(MyParams myParams)
    {
        return PartialView("MyView", GetVM(myParams));
    }
Run Code Online (Sandbox Code Playgroud)

当我想明确清除此缓存(无论现有的缓存持续时间)时,有一些时候(当出现问题时)

无论如何,有完整和部分页面Outputcaching删除缓存页面并运行完整的代码?

注意:我看到这个问题已经在这里围绕asp.net一般问过,但我没看到asp.net-mvc特定的解决方案

我试过这个,但它似乎不起作用:

 public ActionResult ClearCache()
 {
      this.HttpContext.Response.RemoveOutputCacheItem("/MyController/Index.aspx");
      this.HttpContext.Response.RemoveOutputCacheItem("/MyController/MyView.ascx");
 }
Run Code Online (Sandbox Code Playgroud)

Raj*_*ddy 0

对于基于 MVC 的解决方案,你可以这样做

this.HttpContext.Response.RemoveOutputCacheItem(Url.Action("MyAction","MyController",new{ id = 1234}));
Run Code Online (Sandbox Code Playgroud)