【发布时间】:2021-01-04 20:03:55
【问题描述】:
我有一个 WCF 服务,它使用 OutputCacheProfile 来获得一小时的输出缓存时间
<add name="GetVisitorSettingsCache" location="Any" duration="3600" enabled="true" varyByParam="groupid;service;site;ver" />
输出缓存有效,但响应包含标头Vary: *,这会阻止浏览器使用缓存的响应。
我相信我遇到了这里描述的错误:
https://topic.alibabacloud.com/a/introduction-to-an-outputcache-bug-that-accompanied-asp-net-from-10-to-40_1_36_32422553.html
解决方法是致电Response.Cache.SetOmitVaryStar(true);
除了在我的情况下,我有 WCF 服务并且不知道如何在该上下文中使用解决方法
有什么方法可以为 WCF 服务调用 SetOmitVaryStar() 吗? 还有其他解决方法吗?
我尝试以编程方式设置可变标头:
WebOperationContext.Current.OutgoingResponse.Headers.Add("vary", "");
但是没有效果
在 OutputCacheProfile 中设置 location="ServerAndClient" 也没有帮助。
我正在考虑改用 Web API 控制器并使用它: https://github.com/filipw/Strathweb.CacheOutput 但这是最后的手段。
更新
我尝试了下面丁鹏的建议,BeforeSendReply 中的代码试图删除可变标头:
webOperationContext.OutgoingResponse.Headers.Remove("vary");
但是,vary * 标头仍然出现在响应中,就好像输出缓存机制在此点之后将其添加回来一样。
【问题讨论】:
标签: wcf outputcache vary