title: The use and benefits of Response Caching Middleware in ASP.NET Core
body: <p>I wanted to try caching mechanism in my .NET core API project.</p>
  <p>I followed this article to configure the middleware <a href="https://thecodeblogger.com/2021/06/06/middleware-for-response-caching-in-net-core-web-apis/" rel="nofollow noreferrer">https://thecodeblogger.com/2021/06/06/middleware-for-response-caching-in-net-core-web-apis/</a></p>
  <p>Startup.cs</p>
  <pre><code>    public void ConfigureServices(IServiceCollection services)
      {
          services.AddControllers();
  
  
          // Response Caching Middleware
          services.AddResponseCaching(options =&gt;
          {
              // Each response cannot be more than 1 KB 
              options.MaximumBodySize = 1024;
  
              // Case Sensitive Paths 
              // Responses to be returned only if case sensitive paths match
              options.UseCaseSensitivePaths = true;
          });
      }
  
  
  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
  
          app.UseHttpsRedirection();
  
          app.UseRouting();
  
          // Response Caching Middleware
          app.UseResponseCaching();
  
          app.UseAuthorization();
  
          app.UseEndpoints(endpoints =&gt;
          {
              endpoints.MapControllers();
          });
      }
  </code></pre>
  <p>The controller</p>
  <pre><code>   [HttpGet]
      [ResponseCache(NoStore = false, Duration = 600, Location = ResponseCacheLocation.Any)]
      public IEnumerable&lt;WeatherForecast&gt; Get()
      {
          var rng = new Random();
          return Enumerable.Range(1, 5).Select(index =&gt; new WeatherForecast
          {
              Date = DateTime.Now.AddDays(index),
              TemperatureC = rng.Next(-20, 55),
              Summary = Summaries[rng.Next(Summaries.Length)]
          })
          .ToArray();
      }
  </code></pre>
  <p>And I can see in the response this header</p>
  <pre><code>Cache-Control : public,max-age=600
  </code></pre>
  <p>So I put a break point in the controller, whenever I call the api thorugh postman or browsers it hit the api.</p>
  <p>I was assuming adding the header <code>Cache-Control : public,max-age=600</code>
  will create a cache of the response in the client for 600 seconds and it won't hit the backend for each request.</p>
  <p>If not , then what is the actual point of the <code>Cache-Control</code></p>