5

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 programmatically?

Cœur
  • 32,421
  • 21
  • 173
  • 232
andrecarlucci
  • 5,541
  • 4
  • 49
  • 56
  • Possible duplicate of [How to programmatically clear outputcache for controller action method](https://stackoverflow.com/questions/1167890/how-to-programmatically-clear-outputcache-for-controller-action-method) – Cœur Jan 22 '19 at 11:10

3 Answers3

8

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

Community
  • 1
  • 1
eu-ge-ne
  • 27,373
  • 6
  • 69
  • 62
0

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

xandy
  • 26,791
  • 8
  • 57
  • 63
0

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
  • 32,325
  • 3
  • 84
  • 87