From 24544b15e217593cff48cca57b3a7d8a956cb7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Thu, 4 May 2017 01:07:31 -0700 Subject: [PATCH] fix(cache): reduce race condition window by checking for content --- cache.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cache.js b/cache.js index 51acaa8..85d755e 100644 --- a/cache.js +++ b/cache.js @@ -42,6 +42,10 @@ module.exports = class Cache { opts = opts || {} const key = cacheKey(req) return cacache.get.info(this._path, key).then(info => { + return info && cacache.get.hasContent( + this._path, info.integrity, opts + ).then(exists => exists && info) + }).then(info => { if (info && info.metadata && matchDetails(req, { url: info.metadata.url, reqHeaders: new fetch.Headers(info.metadata.reqHeaders),