将Response.RemoveOutputCacheItem与RedisOutputCacheProvider一起使用

 Eva绫波_772 发布于 2022-12-20 17:51

我使用的是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键,但是我绝对可以看到正在缓存的视图。

1 个回答
  • 你尝试过这样的事情吗?

    //  Get the url for the action method:
    var staleItem = Url.Action("Action", "Controller");
    
    //  Remove the item from cache
    Response.RemoveOutputCacheItem(staleItem);
    

    我认为您需要保留对ActionResult的引用。

    祝你好运:)

    PS:也许此链接对您有帮助:Dan Esparza的博客

    2022-12-20 17:52 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有