【问题标题】:Can you force a delete of (page and partialView) OutputCache in asp.net-mvc [duplicate]你能在asp.net-mvc中强制删除(页面和部分视图)OutputCache吗?
【发布时间】:2011-06-27 17:37:33
【问题描述】:

我想要一种简单的方法来清除我的 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));
    }

在某些时候(出现问题时)我想明确清除此缓存(无论现有缓存持续时间如何)

是否有完整和部分页面输出缓存来删除缓存页面并运行完整代码?

注意:我看到这个问题已经在 asp.net 周围被问到了,比如here,但我没有看到 asp.net-mvc 特定的解决方案

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

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

【问题讨论】:

    标签: c# asp.net-mvc outputcache output-caching


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-04-09
      • 1970-01-01
      • 2017-06-05
      • 1970-01-01
      • 2012-12-02
      • 2016-05-21
      • 1970-01-01
      • 2013-09-20
      • 1970-01-01
      相关资源
      最近更新 更多