title: How to return different cache-control headers for different endpoints using ASP.NET minimal APIs?
body: <p>I would like to return a different cache-control header value for different endpoints using ASP.NET minimal APIs.  How do we do this without controllers?</p>
  <p>This can be accomplished using controllers as follows:</p>
  <pre><code>using Microsoft.AspNetCore.Mvc;
  
  namespace CacheTest;
  
  [ApiController]
  public class TestController : ControllerBase
  {
      [HttpGet, Route(&quot;cache&quot;), ResponseCache(Duration = 3600)]
      public ActionResult GetCache() =&gt; Ok(&quot;cache&quot;);
  
      [HttpGet, Route(&quot;nocache&quot;), ResponseCache(Location = ResponseCacheLocation.None, Duration = 0)]
      public ActionResult GetNoCache() =&gt; Ok(&quot;no cache&quot;);
  }
  </code></pre>
  <p>The first endpoint returns the header <code>Cache-Control: public,max-age=3600</code>.</p>
  <p>The second endpoint returns the header <code>Cache-Control: no-cache,max-age=0</code>.</p>