我想要一种简单的方法来清除我的 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 周围被问到了,但我没有看到 asp.net-mvc 特定的解决方案
我已经尝试过了,但它似乎不起作用:
public ActionResult ClearCache()
{
this.HttpContext.Response.RemoveOutputCacheItem("/MyController/Index.aspx");
this.HttpContext.Response.RemoveOutputCacheItem("/MyController/MyView.ascx");
}