I have a WCF Web Service (not Web Api) that looks like this:
public interface ILogsService
{
[OperationContract]
[WebInvoke(UriTemplate = "/Find")]
[Description("-Service description-")]
FindLogsResult FindLogs(LogsFilterRequest request);
}
I would like to know if there's a way (or a better way) to cache the service response by sending HTTP cache headers back to the client.
I've tested and seen that this can be accomplished by using:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddSeconds(30));
But I would like a "cleaner" solution if possible.
This service has aspNetCompatibilityEnabled="true"
and will always be hosted in IIS.
Just to close this question, the only way I could get this working was via HTTP Context:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddSeconds(30));