title: How to stop chrome from caching REST response from WebApi?
body: <p>I am using ASP.NET WebApi and have the following code to stop caching in everything:</p>
  
  <pre><code>public override System.Threading.Tasks.Task&lt;HttpResponseMessage&gt; ExecuteAsync(System.Web.Http.Controllers.HttpControllerContext controllerContext, System.Threading.CancellationToken cancellationToken)
  {
      System.Threading.Tasks.Task&lt;HttpResponseMessage&gt; task = base.ExecuteAsync(controllerContext, cancellationToken);
      task.GetAwaiter().OnCompleted(() =&gt;
                                        {
                                            task.Result.Headers.CacheControl = new CacheControlHeaderValue()
                                            {
                                                NoCache = true,
                                                NoStore = true,
                                                MaxAge = new TimeSpan(0),
                                                MustRevalidate = true
                                            };
                                            task.Result.Headers.Pragma.Add(new NameValueHeaderValue("no-cache"));
                                            task.Result.Content.Headers.Expires = DateTimeOffset.MinValue;
                                        });
      return task;
  }
  </code></pre>
  
  <p>The result headers look like this (chrome):</p>
  
  <pre><code>Cache-Control:no-store, must-revalidate, no-cache, max-age=0
  Content-Length:1891
  Content-Type:application/json; charset=utf-8
  Date:Fri, 19 Jul 2013 20:40:23 GMT
  Expires:Mon, 01 Jan 0001 00:00:00 GMT
  Pragma:no-cache
  Server:Microsoft-IIS/8.0
  </code></pre>
  
  <p>I added the "no-store" after reading about the bug (<a href="https://stackoverflow.com/questions/4146813/how-to-stop-chrome-from-caching">How to stop chrome from caching</a>).</p>
  
  <p>However, no matter what I do, when I do something that navigates me away from this page, and then use the "back" button, chrome always loads from cache:</p>
  
  <pre><code>Request Method:GET
  Status Code:200 OK (from cache)
  </code></pre>
  
  <p>Does anyone have any idea why this is happening? I have confirmed that the server is never hit for this request.</p>