No matter what I do I can't get images returned from a web api too cache, I am seeing a request to the server every time I request the image.
I have tried many permiations for the header setting, here is my latest effort:
public class TestController : ApiController
{
public HttpResponseMessage Get(int id)
{
HttpResponseMessage response = new HttpResponseMessage();
StreamContent streamContent = new StreamContent(File.Open("c:\\1.jpg", FileMode.Open, FileAccess.Read, FileShare.Read));
response.Content = streamContent;
response.Content.Headers.Add("Content-Type", "image/jpeg");
response.Headers.CacheControl = new CacheControlHeaderValue
{
MustRevalidate = true,
Private= false,
MaxAge = TimeSpan.FromMinutes(1),
};
//string hash = new Guid("524DF956-D67A-4D66-A3E0-5E78726A204A").GetHashCode().ToString();
//response.Headers.ETag = new EntityTagHeaderValue(String.Concat("\"", hash, "\""), true);
//response.Content.Headers.LastModified = new DateTimeOffset(new DateTime(2012, 12, 24));
//response.Content.Headers.Expires = new DateTimeOffset(new DateTime(2013, 12, 24));
return response;
}
And this is what the response headers look like when I inspect with chrome:
Cache-Control:must-revalidate, max-age=60 Content-Length:24233
Content-Type:image/jpeg Date:Sun, 14 Apr 2013 22:04:32 GMT
Server:Microsoft-IIS/8.0 X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?Qzpcc291cmNlXFRydW5rXFRlc3RcYXBpXHRlc3RcMQ==?=
Any ideas on how to proceed?