【发布时间】:2018-11-22 20:16:33
【问题描述】:
我有一个 WCF 服务,它确实有效,但确实需要缓存响应。 我遵循了一些在线指导,但收到以下错误:
AspNetCacheProfileAttribute can only be used with GET operations.
我已经在 Postman 中检查了这一点,以完全确定我的客户端代码没有以错误的方式发出请求,结果相同。
界面如下:
public interface INavbar
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
List<Navbar.simpleNav> getNavList();
}
该服务返回一个列表作为 JSON 对象,我尝试添加缓存的 2 个更改是将 AspNetCacheProfile 属性添加到类并将缓存配置文件详细信息添加到我的 web.config。
类的属性:
[AspNetCacheProfile("CacheFor180Seconds")]
web.config:
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="CacheFor180Seconds" duration="180" varyByParam="none"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>
据我所知,这都是非常标准的东西,但可能是我试图以错误的方式做到这一点,因此感谢任何帮助。
非常感谢
【问题讨论】: