我有一个看起来像这样的 WCF Web 服务(不是 Web Api):
public interface ILogsService
{
[OperationContract]
[WebInvoke(UriTemplate = "/Find")]
[Description("-Service description-")]
FindLogsResult FindLogs(LogsFilterRequest request);
}
我想知道是否有一种方法(或更好的方法)通过将 HTTP 缓存标头发送回客户端来缓存服务响应。
我已经测试并看到这可以通过使用来完成:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddSeconds(30));
但如果可能的话,我想要一个“更清洁”的解决方案。
此服务已经aspNetCompatibilityEnabled="true"
并将始终托管在 IIS 中。