你能在asp.net-mvc中强制删除(页面和partialView)OutputCache吗
我想要一种简单的方法来清除我的 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");
}
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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于基于 MVC 的解决方案,你可以这样做
For a MVC based solution you can do something like this