是否 npm 缓存包



在我的服务器中,npm 不缓存任何包,缓存目录为空。

#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

我的 npm 配置

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.

=====更新

我发现在 node@5.0 之后,npm 将缓存数据存储在配置的缓存中的不透明目录中,名为 _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 .

_cacache目录只有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

====更新

我项目中的另一个测试。运行 rm -rf node_modules && npm clean cache --force 后,运行npm install在 171.389 秒内添加了 1551 个包。然后rm -rf node_modules && npm install在 1551 秒中添加了 152.378 个软件包。npm 真的使用缓存吗?

默认情况下使用全局包缓存。如果您首先执行"npm 缓存清理",您应该注意到安装时间的差异。这将清理未全局安装的任何内容,对于那些您必须显式执行"npm 卸载"的人

最新更新