title: Spring MVC cache control headers on JSON content
body: <p>I've got an application where I'm using a text editor to insert images and banners etc. It gets the banner by calling an AJAX request to get the banner, then it compiles the JS.</p>
  
  <p>I want a quick/easy way to cache the request. So I was hoping to just cache the response in the browser cache for 30 seconds.</p>
  
  <p>So I'm trying to get it working in Chrome, but it keeps sending the request and the server keeps responding 200 Ok.</p>
  
  <p>Here's the relevant part of my web config:</p>
  
  <pre><code>WebContentInterceptor webContentInterceptor = new WebContentInterceptor();
  webContentInterceptor.setUseCacheControlHeader(true);
  webContentInterceptor.setUseExpiresHeader(true);
  webContentInterceptor.setUseCacheControlNoStore(true);
  webContentInterceptor.setCacheSeconds(30);
  
  registry.addInterceptor(webContentInterceptor);
  </code></pre>
  
  <p>And the cache control headers as per chrome:</p>
  
  <pre><code>Request URL:https://localhost:8443/admin/banners/json/by_shortcode/banner_test
  Request Method:GET
  Status Code:200 OK
  Request Headersview source
  Accept:*/*
  Accept-Encoding:gzip, deflate, sdch
  Accept-Language:en-US,en;q=0.8
  Connection:keep-alive
  Cookie:sidebar_closed=1; SPRING_SECURITY_REMEMBER_ME_COOKIE=UmljaGFyZC5HaWxsaW5nQGdtYWlsLmNvbToxNDIzODgzOTI1MTY4OmU1OGM2YzVjNjIwMWIyNWM3OTZlMWM5MThjMDc0MDg4; JSESSIONID=70842F221D3172686E406242AD3F5E02
  Host:localhost:8443
  Referer:https://localhost:8443/admin/pages/new
  User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.94 Safari/537.36
  X-Requested-With:XMLHttpRequest
  
  Response Headers
  
  Cache-Control:max-age=30
  Content-Type:application/json;charset=UTF-8
  Date:Mon, 02 Feb 2015 14:03:13 GMT
  Expires:Mon, 02 Feb 2015 14:03:43 GMT
  Pragma:no-cache
  Server:Apache-Coyote/1.1
  Strict-Transport-Security:max-age=31536000 ; includeSubDomains
  Transfer-Encoding:chunked
  X-Content-Type-Options:nosniff
  X-Frame-Options:DENY
  X-XSS-Protection:1; mode=block
  </code></pre>
  
  <p>What I'm wondering is:</p>
  
  <p>a) Why is the browser re-requesting the same request within the 30 second window? I am hoping to cache it for 30seconds.</p>