加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 使用多个VaryByParam删除OutputCache

发布时间:2020-12-15 22:25:34 所属栏目:百科 来源:网络整理
导读:我有这样的动作: [OutputCache(Duration = 3600,Location = OutputCacheLocation.ServerAndClient,VaryByParam = "page;categor;searchString")] public virtual async TaskActionResult Index(int? category,int page = 1,string searchString = null) 此
我有这样的动作:

[OutputCache(Duration = 3600,Location = OutputCacheLocation.ServerAndClient,VaryByParam = "page;categor;searchString")]
    public virtual async Task<ActionResult> Index(int? category,int page = 1,string searchString = null)

此操作可以具有多个缓存结果.到目前为止它的罚款.但是当我发布新内容时,我想删除所有这些多个缓存结果.

我知道我可以在foreach中使用RemoveOutputCacheItem和url列表.

var urls = new List<string>();
foreach (var url in urls)
{
   HttpResponse.RemoveOutputCacheItem(url);
}

但为此我必须与我的数据库建立多个连接并获取类别,页面,即使我以某种方式得到所有搜索字符串,它仍然会造成太多麻烦.

我的问题是,有没有更好的方法一次删除所有这些缓存?

解决方法

Is there a better way to remove all those cache at once

不是我知道的.但是您可以删除特定控制器操作方法的缓存项,如下所示(假设您的控制器名称为controller1).从Clearing the ASP.Net MVC Cache采取的想法

HttpResponse.RemoveOutputCacheItem(Url.Action("Index","controller1",new { category = 1234  }));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读