views:

584

answers:

3

Hi,

I'm using the OutputCache attribute to cache my action's html output at the server-side.

Fine, it works, but now I have a situation where the content changes rarely, but when it does, it's critical for the user to see the new data the very next request.

So, is there a way to abort the page cache duration programatically?

Thanks in advance,

André Carlucci

A: 

You can extend the OutputCacheAttribute to create your own cache mechanism that allow dependency similar to the original ASP.net caching.

xandy
+5  A: 

Yes, it is possible using HttpResponse.RemoveOutputCacheItem Method. Check this question:

eu-ge-ne
A: 

You could also use HttpCachePolicy.AddValidationCallback(). The general idea is that when the page is rendered and inserted into the cache, this callback is inserted along with the page. Upon page retrieval from the cache, the callback is invoked and makes the final determination as to whether the cached page is stale (and should be booted) or valid (and should be served). See the AuthorizeAttribute source for an example. If a page becoming stale is really rare, though, you may be better served by the RemoveOutputCacheItem() method as mentioned in the other response.

Levi