【发布时间】:2017-03-02 09:15:34
【问题描述】:
我已经使用 Azure Redis 服务实现了 Redis OutputCache (Microsoft.Web.RedisOutputCacheProvider)。
上面需要缓存的页面:
<%@ OutputCache VaryByParam="*" Duration="600" %>
访问随机页面后,我检查 Redis 数据库中的密钥是否已保存,例如:/_a2/monitor.aspx
所以运行下面的代码行,将删除这个缓存项(并且它起作用了)。
HttpResponse.RemoveOutputCacheItem("/monitor.aspx", "RedisOutputCache")
现在我更新了相同的页面,添加了 vSphereByCustom 和 OutputCache 指令:
<%@ OutputCache VaryByParam="*" varyByCustom="userhash" Duration="600" %>
现在访问该页面并检查 Redis 数据库中的密钥,它保存为:/_a2/monitor.aspxHQFCNuserhashVcc6ef5b7173286704cef942d5577b88bd81f2cce71a0dcdc8676d3a815e68b59DE
您会看到添加的 userhash 哈希值,这很好并且按预期工作。
但是现在问题来了:如何清除这个缓存项。
这不起作用:
`HttpResponse.RemoveOutputCacheItem("/monitor.aspx", "RedisOutputCache")`
还尝试过:
HttpResponse.RemoveOutputCacheItem("/monitor.aspx?userhash=cc6ef5b7173286704cef942d5577b88bd81f2cce71a0dcdc8676d3a815e68b59", "RedisOutputCache")
并且还尝试过:
HttpResponse.RemoveOutputCacheItem("/monitor.aspx {userhash:cc6ef5b7173286704cef942d5577b88bd81f2cce71a0dcdc8676d3a815e68b59}", "RedisOutputCache")
还尝试结合上述代码使用以下一些选项:
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 助手访问这个对象。
欢迎任何帮助!
乔尔
【问题讨论】:
-
这个问题你解决了吗,有更新吗?
标签: asp.net redis outputcache azure-redis-cache