如标题所示,如何清除客户端的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¶2=value2¶N=valueN&no_cache=" + new Date().getTicksUTC();
alert(strURL);
</script>
关于asp.net-mvc - 在客户端清除outputcache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10107447/