I am a beginner in ASP.Net MVC 5. And I have applied caching in certain controller actions. Now I want an action to clear the client cache. How to achieve it. Here is what I have now:
我是ASP.Net MVC 5的初学者。我在某些控制器操作中应用了缓存。现在我想要一个动作来清除客户端缓存。如何实现它。这就是我现在拥有的:
[OutputCache(Duration = 10800, Location = OutputCacheLocation.Client)]
public PartialViewResult Temp()
{
return PartialView("Index", data);
}
Link I looked: ClearCache
链接我看了:ClearCache
It has a solution which tells to use: Response.Cache.SetNoStore
它有一个解决方案,告诉使用:Response.Cache.SetNoStore
But it will tell client to never cache right? I am lost here. Please guide me. Under certain scenario only I want the cache to get cleared. In other scenarios caching should take place as expected.
但它会告诉客户永远不会缓存吗?我迷失在这里。请指导我。在某些情况下,我只想清除缓存。在其他情况下,缓存应按预期进行。
1 个解决方案
#1
0
Add this meta
tag in your layout page (in html head):
在您的布局页面中添加此元标记(在html头中):
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
and also add golbal.asax.cs
:
并添加golbal.asax.cs:
protected void Application_AcquireRequestState(Object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
HttpContext.Current.Response.AddHeader("Expires", "0");
}
#1
0
Add this meta
tag in your layout page (in html head):
在您的布局页面中添加此元标记(在html头中):
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
and also add golbal.asax.cs
:
并添加golbal.asax.cs:
protected void Application_AcquireRequestState(Object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
HttpContext.Current.Response.AddHeader("Expires", "0");
}