title: ASP.NET Core 2.0 - Http Response Caching Middleware - Nothing cached
body: <p>I created a new solution from WebApi .Net Core 2.0 template in Visual Studio.
  I added the following in startup.</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddMvc();
      services.AddHttpCacheHeaders(opt =&gt; opt.MaxAge = 600);
      services.AddResponseCaching();
  }
  
  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  {
      if (env.IsDevelopment())
      {
          app.UseDeveloperExceptionPage();
      }
  
      app.UseResponseCaching();
      app.UseHttpCacheHeaders();
      app.UseMvc();
  }
  </code></pre>
  
  <p>Then, with postman, I hit <code>http://localhost:xxxx/api/values</code> which is a endpoint created by the template and that returns <code>["value1","value2"]</code></p>
  
  <p>Note that I made sure that Postman doesn't send no-cache header (in Postman settings).</p>
  
  <p>The <code>HttCacheHeaders</code> service comes from that <a href="https://github.com/KevinDockx/HttpCacheHeaders" rel="nofollow noreferrer">repo</a>. It adds HTTP Cache Headers. So my endpoint response header is:</p>
  
  <ul>
  <li>Cache-Control: public,max-age=600</li>
  <li>Content-Type: application/json; charset=utf-8</li>
  <li>Date: Fri, 29 Sep 2017 14:02:29 GMT</li>
  <li>ETag: C5DFA8974BB722D27E71EE50D3D14625</li>
  <li>Expires: Fri, 29 Sep 2017 14:03:29 GMT</li>
  <li>Last-Modified: Fri, 29 Sep 2017 14:02:29 GMT</li>
  <li>Server: Kestrel</li>
  <li>Transfer-Encoding: chunked</li>
  <li>Vary: Accept, Accept-Language, Accept-Encoding</li>
  <li>X-Powered-By: ASP.NET</li>
  <li>X-SourceFiles: =?UTF-8?B?................</li>
  </ul>
  
  <p>The problem is that nothing gets cached. the <code>Ouput</code> windows only shows <code>The response could not be cached for this request.</code></p>
  
  <p>So I'm a bit lost on how to use <code>ASP.NET Core ResponseCaching Middleware</code>.</p>
  
  <p><b>Update</b>
  <br/><br/>
  If I don't use the <code>HttCacheHeaders</code> service but add <code>[ResponseCache(Duration = 600)]</code> to the action of my controller, the cache works.<br>
  Note that reason that I want to use <code>HttCacheHeaders</code> is for <code>ETag</code> and <code>Last-Modified</code> to later do Validation Caching as well as Expiration Caching.</p>