Abort OutputCache duration programmatically in asp.net mvc

萝らか妹 提交于 2020-01-01 05:45:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!