Skip to content

Commit

Permalink
feat(cache): add flag to choose cache strategy if stale
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanebachelier committed Apr 24, 2016
1 parent 44f7d36 commit d228174
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function cache (config = {}) {
config.maxAge = config.maxAge || 0
config.readCache = config.readCache || readCache
config.serialize = config.serialize || serialize
config.clearOnStale = config.clearOnStale !== undefined ? config.clearOnStale : true

config.exclude = config.exclude || {}
config.exclude.query = config.exclude.query || true
Expand Down Expand Up @@ -56,7 +57,7 @@ function cache (config = {}) {
return config.readCache(req, config.log)(value)
.catch(err => {
// clean up cache if stale
err.reason === 'cache-stale' ? config.store.removeItem(uuid).then(f) : f()
config.clearOnStale && err.reason === 'cache-stale' ? config.store.removeItem(uuid).then(f) : f()
})
})
}
Expand Down

0 comments on commit d228174

Please sign in to comment.