Reputation: 1131
As the title says, how can i clear Outputcache on client side? I have several ajax calls that needs to be cleared after user does some specific actions.
I tried:
Response.RemoveOutputCacheItem(Url.Action("Action", "Controller"));
But it didn't work.
I even tried to expire it mannually (even though this would be a bad approach):
Response.Expires = 0;
Response.ExpiresAbsolute = DateTime.Now.AddMinutes(-1);
Response.AddHeader("pragma", "no-cache");
Response.AddHeader("cache-control", "private");
Response.CacheControl = "no-cache";
That didn't worked out too.
Just to be clear, i'm using OutputcacheLocation = Client
. If i set it to Server
the examples above work flawlessly.
Upvotes: 3
Views: 1949
Reputation: 82356
If what you need is the axax call to return different data each time despite caching, when called with the same arguments, the only reliable way is to add another variable in the query string, which is always different, e.g. the time down to the millisecond.
Here's how I do it (parameter 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>
Upvotes: 3
Reputation: 769
You can't. Once you set the cache location to client, you have given the client the responsibility to manage it.
Upvotes: -2