Abort OutputCache duration programmatically in asp.net mvc
Asked Answered
C

3

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?

Carangid answered 29/7, 2009 at 14:21 Comment(1)
Possible duplicate of How to programmatically clear outputcache for controller action methodKrispin
S
8

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

Straitlaced answered 29/7, 2009 at 18:10 Comment(0)
S
0

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

Stanislas answered 29/7, 2009 at 14:52 Comment(0)
U
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.

Upsurge answered 29/7, 2009 at 21:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.