I have a WCF web service returning JSON.
[OperationContract] [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)] Stream GetStuff(int arg);
And I use this method to convert the graph of objects to JSON:
private static Stream ToJson(object obj) { JavaScriptSerializer serializer = new JavaScriptSerializer(); string json = serializer.Serialize(obj); if (WebOperationContext.Current != null) { OutgoingWebResponseContext outgoingResponse = WebOperationContext.Current.OutgoingResponse; outgoingResponse.ContentType = "application/json; charset=utf-8"; outgoingResponse.Headers.Add(HttpResponseHeader.CacheControl, "max-age=604800");
I would like the answers to be cached in the browser, but the browser still generates If-Modified-Since calls to the server, which are played using 304 Not Modified . I would like the browser to cache and use the response, each time calling an If-Modified-Since call to the server.
I noticed that although I specify Cache-Control "max-age=604800" in the code, the response header sent by WCF is Cache-Control no-cache,max-age=604800 . Why is WCF adding a no-cache part and how can I stop it from adding it?
source share