title: How to enable HTTP response caching in Spring Boot
body: <p>I have implemented a REST server using Spring Boot 1.0.2. I'm having trouble preventing Spring from setting HTTP headers that disable HTTP caching.</p>
  
  <p>My controller is as following:</p>
  
  <pre><code>@Controller
  public class MyRestController {
      @RequestMapping(value = "/someUrl", method = RequestMethod.GET)
      public @ResponseBody ResponseEntity&lt;String&gt; myMethod(
              HttpServletResponse httpResponse) throws SQLException {
          return new ResponseEntity&lt;String&gt;("{}", HttpStatus.OK);
      }
  }
  </code></pre>
  
  <p>All HTTP responses contain the following headers:</p>
  
  <pre><code>Cache-Control: no-cache, no-store, max-age=0, must-revalidate
  Expires: 0
  Pragma: no-cache
  </code></pre>
  
  <p>I've tried the following to remove or change those headers:</p>
  
  <ol>
  <li>Call <code>setCacheSeconds(-1)</code> in the controller.</li>
  <li>Call <code>httpResponse.setHeader("Cache-Control", "max-age=123")</code> in the controller.</li>
  <li>Define <code>@Bean</code> that returns <code>WebContentInterceptor</code> for which I've called <code>setCacheSeconds(-1)</code>.</li>
  <li>Set property <code>spring.resources.cache-period</code> to -1 or a positive value in <code>application.properties</code>.</li>
  </ol>
  
  <p>None of the above have had any effect. How do I disable or change these headers for all or individual requests in Spring Boot?</p>