Skip to content

Commit

Permalink
Added respect for cache-control max-age header
Browse files Browse the repository at this point in the history
A cache-control response header with a max-age value will now override
any configured shelfLife by default.  Can be ignored by configuring
ignoreCacheControl to true
  • Loading branch information
Edward de Groot committed Sep 14, 2011
1 parent 5edf526 commit 20720de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/single.coffee
Expand Up @@ -7,5 +7,5 @@ test = ->
console.log "\t#{item.results[0].text}"
setTimeout(test, 1000)

pantry.configure { shelfLife: 5, verbosity: 'DEBUG' }
pantry.configure { shelfLife: 5, verbosity: 'DEBUG', ignoreCacheControl: true }
test()
4 changes: 4 additions & 0 deletions src/pantry.coffee
Expand Up @@ -139,6 +139,10 @@ class StockedItem extends EventEmitter

request @options, (error, response, body) =>

# cache-control header max-age value will by default overide configured shelfLife
match = /max-age=(\d+)/.exec(response.headers['cache-control'])
@options.shelfLife = parseInt(match[1]) if match and not @options.ignoreCacheControl

unless error?
switch response.statusCode
when 304 # cached data is still good. keep using it
Expand Down

0 comments on commit 20720de

Please sign in to comment.