Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用varyByCustom时如何使用:HttpResponse.RemoveOutputCacheItem_Asp.net_Redis_Outputcache_Azure Redis Cache - Fatal编程技术网

Asp.net 使用varyByCustom时如何使用:HttpResponse.RemoveOutputCacheItem

Asp.net 使用varyByCustom时如何使用:HttpResponse.RemoveOutputCacheItem,asp.net,redis,outputcache,azure-redis-cache,Asp.net,Redis,Outputcache,Azure Redis Cache,我已经使用Azure Redis服务实现了Redis OutputCache(Microsoft.Web.RedisOutputCacheProvider) 我发现了类似的未回答/未解决的问题和问题 在需要缓存的页面顶部: 访问随机页面后,我检查Redis数据库中的密钥是否已保存,如:/\u a2/monitor.aspx 因此,运行下面的代码行将删除此缓存项(并且它工作正常) 现在,我已经更新了相同的页面,添加了varyByCustom和OutputCache指令: 现在,访问页面并检查R

我已经使用Azure Redis服务实现了Redis OutputCache(Microsoft.Web.RedisOutputCacheProvider)

我发现了类似的未回答/未解决的问题和问题

在需要缓存的页面顶部:

访问随机页面后,我检查Redis数据库中的密钥是否已保存,如:/\u a2/monitor.aspx

因此,运行下面的代码行将删除此缓存项(并且它工作正常)

现在,我已经更新了相同的页面,添加了varyByCustom和OutputCache指令:

现在,访问页面并检查Redis数据库中的密钥,它的保存方式如下:/_a2/monitor.aspxhqfcnuershashvcc6ef5b7173286704cef942d5577b88bd81f2ce71a0dc8676d3a815e68b59de

您可以看到添加的userhash散列值,这很好,并且按照预期工作

但现在问题来了:如何清除此缓存项

这不起作用:

`HttpResponse.RemoveOutputCacheItem("/monitor.aspx", "RedisOutputCache")`
还尝试:
HttpResponse.RemoveOutputCacheItem(“/monitor.aspx?userhash=CC6EF5B7173286704CEF942D5577B88BD81F2CCE71A0DC8676D3A815E68B59”,“重新输出缓存”)

并尝试:
HttpResponse.RemoveOutputCacheItem(“/monitor.aspx{userhash:CC6EF5B7173286704CEF942D5577B88BD81F2CCE71A0DC8676D3A815E68B59}”,“重新输出缓存”)

还尝试结合上述代码使用以下一些选项:

Response.Cache.SetVaryByCustom("userhash")
Response.AddCacheItemDependency("action")
HttpContext.Current.Cache.Item("action") = "test"
Response.Cache.VaryByParams("userhash") = True
HttpResponse.RemoveOutputCacheItem("/monitor.aspx")
有没有办法使用varyByCustom选项删除上的此缓存项

我不使用system.web.mvc对象。因此,我无法访问URL帮助器的此对象

欢迎任何帮助


Joël

根据您的描述,我尝试实现将缓存存储到文件中,以测试我这方面的问题。这是我的测试结果,你可以参考一下

my Monitor.aspx的输出缓存

访问上述页面时,我将从OutputFileCacheProvider获得以下日志,如下所示:

在我访问另一个.aspx以清除缓存后,当前的DateTime字符串将在我的monitor.aspx页面中刷新

注意:调用
HttpResponse.RemoveOutputCacheItem(“/monitor.aspx”)
的方法与从另一个.aspx端点清除缓存的方法相同


VaryByParam
varyByCustom
在我这方面都可以按预期工作。我认为您可以在OutputCacheProvider中添加日志,并尝试查找是否遗漏了某些内容。

嗨,Bruce,谢谢您的回复。我不确定Microsoft.Web.RedisOutputCacheProvider是否有调试日志记录选项。但我注意到了一些事情。在第二个图像中,仍然没有删除使用VaryByCustom=“userhash”参数的缓存项。它删除了userhash中的项目。所以我认为这是RedisOutputCacheProvider中没有提供的。谢谢!J在使用VaryByCustom时,您是否尝试将
VaryByParam
更改为
None
:您是否解决了此问题,是否有任何更新?
Response.Cache.SetVaryByCustom("userhash")
Response.AddCacheItemDependency("action")
HttpContext.Current.Cache.Item("action") = "test"
Response.Cache.VaryByParams("userhash") = True
HttpResponse.RemoveOutputCacheItem("/monitor.aspx")