From 8129677dcd596bdbbc45c772b7708fff45a8259b Mon Sep 17 00:00:00 2001 From: Stephane BACHELIER Date: Sat, 20 Feb 2016 00:22:45 +0100 Subject: [PATCH] feat(cache): cleanup cache entry if stale --- lib/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index c0bf00b..79ac789 100644 --- a/lib/index.js +++ b/lib/index.js @@ -53,8 +53,9 @@ function cache (config = {}) { return store.getItem(uuid).then(value => { return config.readCache(req, config.log)(value) - .catch(err => { // eslint-disable-line handle-callback-err - f() + .catch(err => { + // clean up cache if stale + err.reason === 'cache-stale' ? store.removeItem(uuid).then(f) : f() }) }) }