WebAPI OutputCache cache invalidation

泪湿孤枕 提交于 2019-12-10 20:14:29

问题


I have the following caching attribute on my controller method:

 [CacheOutput(ClientTimeSpan = 14400, ServerTimeSpan = 14400)]

I am attempting to clear the cache. However, after running this line of code:

 //clear cache   
 cache.RemoveStartsWith(Configuration.CacheOutputConfiguration().MakeBaseCachekey("BeamsController", "Get"));

I am still getting a 304 not-modified response without the controller method being invoked.

I am using this library https://github.com/filipw/AspNetWebApi-OutputCache


回答1:


 [InvalidateCacheOutput("Get", typeof(BeamsController))] 

seems to work, instead of 'manual invalidation' (RemoveStartsWith), above.

In fact, after reading the source code of the attribute, it appears that the documentation is wrong and it should be:

cache.RemoveStartsWith(Configuration.CacheOutputConfiguration().MakeBaseCachekey("Beams", "Get"));

which works as expected, calling the method.



来源:https://stackoverflow.com/questions/28325060/webapi-outputcache-cache-invalidation

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