parent
9dbe412783
commit
9b9ded57e7
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue