Skip to content

Commit 9b9ded5

Browse files
committed
Fix caching issue
Fixes unpkg#138
1 parent 9dbe412 commit 9b9ded5

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

modules/utils/getNpmPackageInfo.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,17 @@ function getNpmPackageInfo(packageName) {
1515
} else {
1616
fetchNpmPackageInfo(packageName).then(value => {
1717
if (value == null) {
18-
resolve(null);
19-
2018
// Cache 404s for 5 minutes. This prevents us from making
2119
// unnecessary requests to the registry for bad package names.
2220
// In the worst case, a brand new package's info will be
2321
// available within 5 minutes.
2422
cache.setex(key, 300, notFound);
23+
resolve(null);
2524
} else {
26-
resolve(value);
27-
2825
// Cache valid package info for 1 minute. In the worst case,
2926
// new versions won't be available for 1 minute.
30-
cache.setnx(key, JSON.stringify(value), (error, reply) => {
31-
if (reply === 1) cache.expire(key, 60);
32-
});
27+
cache.setex(key, 60, JSON.stringify(value));
28+
resolve(value);
3329
}
3430
}, reject);
3531
}

0 commit comments

Comments
 (0)