问题
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?
回答1:
Yes, it is possible using HttpResponse.RemoveOutputCacheItem Method. Check this question:
- SO - How to programmatically clear outputcache for controller action method
回答2:
You can extend the OutputCacheAttribute to create your own cache mechanism that allow dependency similar to the original ASP.net caching.
回答3:
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.
来源:https://stackoverflow.com/questions/1200616/abort-outputcache-duration-programmatically-in-asp-net-mvc