npm_lazy icon indicating copy to clipboard operation
npm_lazy copied to clipboard

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

Open sneak opened this issue 9 years ago • 2 comments

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.

sneak avatar Sep 29 '15 01:09 sneak

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.

arw180 avatar Oct 08 '15 13:10 arw180

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

ncoquelet avatar Mar 08 '16 09:03 ncoquelet