mixu/npm_lazy

npm_lazy contacts registry on every request even if metadata is present and fresher than cacheAge

sneak opened this issue · 2 comments

sneak commented

Even when I have fresh metadata files only minutes old (my cacheAge is set to 120 minutes), every single registry request to npm_lazy incurs a small roundtrip to the upstream server to check for freshness.

Simulating a network failure to force it to serve the locally cached version would require significantly more logic in my testing environment.

The whole point of a local cache is to avoid network roundtrips. It's latency, not throughput - the amount of data that is cached is under 50 megabytes, which is a fast download. It's the hundreds of roundtrips to fetch metadata that slow it down. There should be an option to operate entirely locally if the metadata is less than cacheAge old, and hit the upstream registry only if it is older (even avoiding the HEAD request to check for modifications). I really don't need to worry about package updates in the last hour. If I did, I wouldn't be using a cache.

You can get this behavior by modifying the cacheAge in https://github.com/mixu/npm_lazy/blob/master/config.js. The default is zero (meaning it will request metadata updates every time), despite documentation in the README that says the default is an hour.

For information, the unit of cacheAge is millisecond.
So if you want to set the cache age to avoid registry request for the next 120 minutes, you need to set
cacheAge: 7200000 or cacheAge: 120 * 60 * 1000