清除客户端的outputcache

时间:2012-04-11 13:58:48

标签: 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,则上述示例可以完美运行。

2 个答案:

答案 0 :(得分:3)

如果你需要的是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> 

答案 1 :(得分:-2)

你做不到。将缓存位置设置为客户端后,您已授权客户端管理它。

相关问题