简体   繁体   中英

Does npm cache packages?

In my server, npm doesn't cache any package and cache directory is empty.

#www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ nvm current
v9.4.0
# www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ npm config get cache
/home/www/.npm
# www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ ls
anonymous-cli-metrics.json  _cacache  _locks

My npm config

www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ npm config ls
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.6.0 node/v9.4.0 linux x64"

; node bin location = /home/www/.nvm/versions/node/v9.4.0/bin/node
; cwd = /home/www/.npm
; HOME = /home/www
; "npm config ls -l" to show all defaults.

===== update

I found that after node@5.0 npm stores cache data in an opaque directory within the configured cache, named _cacache. https://docs.npmjs.com/cli/cache

www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ du -h --max-depth=1
56M ./_cacache
4.0K    ./_locks
8.0K    ./node-sass
56M .

The _cacache directory is just 56MB

www@iZ2zefuufnen6rfx7c81u7Z:~/.npm$ npm cache verify
Cache verified and compressed (~/.npm/_cacache):
Content verified: 1164 (39196729 bytes)
Index entries: 1167
Finished in 1.321s

==== update

Another test in my project. After run rm -rf node_modules && npm clean cache --force , then run npm install added 1551 packages in 171.389s. And then rm -rf node_modules && npm install added 1551 packages in 152.378s. Does npm really use cache?

Global package cache is used by default. You should notice a difference in your install timings if you first do an "npm cache clean". That will clean up anything not installed globally, for those you will have to explicitly do an "npm uninstall"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM