asp.net-mvc - 在客户端清除outputcache

标签 asp.net-mvc outputcache

如标题所示,如何清除客户端的Outputcache?我有几个ajax调用,需要在用户执行某些特定操作后清除。

我试过了:

Response.RemoveOutputCacheItem(Url.Action("Action", "Controller"));


但这没有用。

我什至尝试手动使它过期(即使这是一个不好的方法):

                Response.Expires = 0;
                Response.ExpiresAbsolute = DateTime.Now.AddMinutes(-1);
                Response.AddHeader("pragma", "no-cache");
                Response.AddHeader("cache-control", "private");
                Response.CacheControl = "no-cache";


那也没有解决。

为了清楚起见,我正在使用OutputcacheLocation = Client。如果我将其设置为Server,则上面的示例可以正常工作。

最佳答案

如果您需要的是axax调用,尽管进行了缓存但仍每次都返回不同的数据,当使用相同的参数调用时,唯一可靠的方法是在查询字符串中添加另一个变量,该变量始终是不同的,例如时间降至毫秒。

这是我的操作方法(参数no_cache):

<script type="text/javascript">
Date.prototype.getTicksUTC = function() 
{
    return Date.parse(this.toUTCString()) + this.getUTCMilliseconds();
} // End Function getTicksUTC


Date.prototype.getTicksGMT = function() 
{
    return Date.parse(this.toGMTString()) + this.getMilliseconds();
} // End Function getTicksGMT

var strURL= "http://localhost/ajax/whateverhandler.ashx?param1=value1&para2=value2&paraN=valueN&no_cache=" + new Date().getTicksUTC();
alert(strURL);

</script> 

关于asp.net-mvc - 在客户端清除outputcache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10107447/

相关文章:

asp.net - 对于大型企业项目来说,ASP.NET MVC 是一个糟糕的选择吗?

asp.net - 如何测量 Live ASP.NET MVC Web 应用程序的内存使用情况?

asp.net-mvc - #if !DEBUG [RequireHttps] 在服务器上不起作用

c# - 将 ASP.NET MVC Controller 属性注入(inject)服务层依赖项?

azure - Azure 中具有 MVC 和 ASP.NET Core 的 Outputcache IIS

.net - Web API 缓存

javascript - 如何确保永远不会缓存动态生成的 javascript 文件?

asp.net-mvc - 通过生成 Entity Framework 脚手架 API Controller 错误使用 Web API

c# - 不缓存 [ChildActionOnly] 操作在 ASP.NET MVC 中不起作用

caching - 停止 EPiServer 在发布时清除输出缓存