的WebAPI的OutputCache缓存失效 [英] WebAPI OutputCache cache invalidation

查看:2220
本文介绍了的WebAPI的OutputCache缓存失效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下缓存属性我控制器的方法:

  [CacheOutput(ClientTimeSpan = 14400,ServerTimeSpan = 14400)

我试图清除缓存。但是,运行此行code后:

  //清除缓存
 cache.RemoveStartsWith(Configuration.CacheOutputConfiguration()MakeBaseCachekey(BeamsController,GET));

我仍然得到被调用,而不在控制器方法304未修改响应。

我使用这个库 https://github.com/filipw/AspNetWebApi-OutputCache


解决方案

  [InvalidateCacheOutput(获取的typeof(BeamsController))]

似乎工作,而不是'人工失效( RemoveStartsWith )之上。

在实际上,读取属性的源$ C ​​$℃后,看来该文档是错误的,它应该是:

<$p$p><$c$c>cache.RemoveStartsWith(Configuration.CacheOutputConfiguration().MakeBaseCachekey(\"Beams\", 得到));

这正如所料,调用该方法的工作原理。

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

解决方案

 [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.

这篇关于的WebAPI的OutputCache缓存失效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆