If-Modified-Since request header can cause a Cache-Control negative max-age
-
We found a peculiar issue where if a request’s
If-Modified-Since
date does not match the cached response’sLast-Modified
date, it results in a negativeCache-Control max-age
, which we found is interpreted by Akamai to cache the response forever (at least in the configuration we’re using).To reproduce, hit a URL (e.g. a feed) a couple times to ensure Batcache saves the response in the cache:
$ curl -Gis 'https://local.example.com/tag/lorem/feed/' $ curl -Gis 'https://local.example.com/tag/lorem/feed/'
Example headers returned:
HTTP/1.1 200 OK Date: Thu, 24 Jan 2013 00:30:46 GMT Vary: Cookie,Accept-Encoding Last-Modified: Wed, 09 Jan 2013 19:38:59 GMT Cache-Control: max-age=300, must-revalidate ETag: "726c4bddc70a4ccc0d6c0b77abb97e20" Content-Length: 3380 Content-Type: text/xml; charset=UTF-8
Note the
Last-Modified: Wed, 09 Jan 2013 19:38:59 GMT
. If you do a request with this time as theIf-Modified-Since
:$ curl -Gis -H "If-Modified-Since: Wed, 09 Jan 2013 19:38:59 GMT" 'https://local.example.com/tag/lorem/feed/'
You get the
304
response as expected:HTTP/1.1 304 Not Modified Date: Thu, 24 Jan 2013 00:32:53 GMT Vary: Cookie
But if you try supplying a different date as the
If-Modified-Since
date:$ curl -Gis -H "If-Modified-Since: Wed, 09 Jan 2013 19:00:00 GMT" 'https://local.example.com/tag/lorem/feed/' HTTP/1.1 200 OK Date: Thu, 24 Jan 2013 00:35:12 GMT Vary: Cookie,Accept-Encoding Last-Modified: Wed, 09 Jan 2013 19:38:59 GMT Cache-Control: max-age=-1227073, must-revalidate ETag: "726c4bddc70a4ccc0d6c0b77abb97e20" Content-Length: 3380 Content-Type: text/xml; charset=UTF-8
Now you get a negative value for the
max-age
.The patch is simply to prevent negative values: https://gist.github.com/4616240
- The topic ‘If-Modified-Since request header can cause a Cache-Control negative max-age’ is closed to new replies.