WebAPI OutputCache cache invalidation

2019-07-23 18:13发布

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条回答
走好不送
2楼-- · 2019-07-23 19:12
 [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.

查看更多
登录 后发表回答