parent
9dbe412783
commit
9b9ded57e7
|
@ -15,21 +15,17 @@ function getNpmPackageInfo(packageName) {
|
||||||
} else {
|
} else {
|
||||||
fetchNpmPackageInfo(packageName).then(value => {
|
fetchNpmPackageInfo(packageName).then(value => {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
resolve(null);
|
|
||||||
|
|
||||||
// Cache 404s for 5 minutes. This prevents us from making
|
// Cache 404s for 5 minutes. This prevents us from making
|
||||||
// unnecessary requests to the registry for bad package names.
|
// unnecessary requests to the registry for bad package names.
|
||||||
// In the worst case, a brand new package's info will be
|
// In the worst case, a brand new package's info will be
|
||||||
// available within 5 minutes.
|
// available within 5 minutes.
|
||||||
cache.setex(key, 300, notFound);
|
cache.setex(key, 300, notFound);
|
||||||
|
resolve(null);
|
||||||
} else {
|
} else {
|
||||||
resolve(value);
|
|
||||||
|
|
||||||
// Cache valid package info for 1 minute. In the worst case,
|
// Cache valid package info for 1 minute. In the worst case,
|
||||||
// new versions won't be available for 1 minute.
|
// new versions won't be available for 1 minute.
|
||||||
cache.setnx(key, JSON.stringify(value), (error, reply) => {
|
cache.setex(key, 60, JSON.stringify(value));
|
||||||
if (reply === 1) cache.expire(key, 60);
|
resolve(value);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}, reject);
|
}, reject);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue