c# – 将Response.RemoveOutputCacheItem与RedisOutputCacheProvider一起使用
作者:互联网
我正在使用Microsoft RedisOutputCacheProvider,并且有一个非常简单的PartialView,我根据当前用户的SessionId通过VaryByCustom进行缓存:
[OutputCache(VaryByCustom = "User", Duration = 3600)]
[ChildActionOnly]
public ActionResult Notifications()
{
return PartialView("Partials/Notifications");
}
这很好,并且按预期缓存,但是我想从另一个页面手动使这个OutputCache过期.我试过了:
Response.RemoveOutputCacheItem("/Controller/Notifications");
但这似乎不起作用.我也无法通过我的Redis商店或我的后端代码看到任何OutputCache键,但我绝对可以看到缓存的视图.
解决方法:
你尝试过这样的事吗?
// Get the url for the action method:
var staleItem = Url.Action("Action", "Controller");
// Remove the item from cache
Response.RemoveOutputCacheItem(staleItem);
我认为您需要保留对ActionResult的引用.
祝你好运:)
PS:也许这个链接可以帮到你:The Blog of Dan Esparza
标签:c,caching,redis,outputcache,stackexchange-redis 来源: https://codeday.me/bug/20190624/1277273.html