From 9b9ded57e7d3110be72ba5becb6de27154ea5ee2 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Thu, 18 Oct 2018 17:41:10 -0700 Subject: [PATCH] Fix caching issue Fixes #138 --- modules/utils/getNpmPackageInfo.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/modules/utils/getNpmPackageInfo.js b/modules/utils/getNpmPackageInfo.js index b027084..77b730d 100644 --- a/modules/utils/getNpmPackageInfo.js +++ b/modules/utils/getNpmPackageInfo.js @@ -15,21 +15,17 @@ function getNpmPackageInfo(packageName) { } else { fetchNpmPackageInfo(packageName).then(value => { if (value == null) { - resolve(null); - // Cache 404s for 5 minutes. This prevents us from making // unnecessary requests to the registry for bad package names. // In the worst case, a brand new package's info will be // available within 5 minutes. cache.setex(key, 300, notFound); + resolve(null); } else { - resolve(value); - // Cache valid package info for 1 minute. In the worst case, // new versions won't be available for 1 minute. - cache.setnx(key, JSON.stringify(value), (error, reply) => { - if (reply === 1) cache.expire(key, 60); - }); + cache.setex(key, 60, JSON.stringify(value)); + resolve(value); } }, reject); }