简体   繁体   English

npm缓存包吗?

[英]Does npm cache packages?

In my server, npm doesn't cache any package and cache directory is empty. 在我的服务器中,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

My npm config 我的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.

===== update ===== 更新

I found that after node@5.0 npm stores cache data in an opaque directory within the configured cache, named _cacache. 我发现在node@5.0之后,npm将缓存数据存储在配置缓存中的一个不透明目录中,名为_cacache。 https://docs.npmjs.com/cli/cache 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 _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

==== 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. 运行rm -rf node_modules && npm clean cache --forcerun npm install在171.389s中添加了1551个软件包。 And then rm -rf node_modules && npm install added 1551 packages in 152.378s. 然后rm -rf node_modules && npm install在152.378s中添加了1551个包。 Does npm really use cache? npm真的使用缓存吗?

Global package cache is used by default. 默认情况下使用全局包缓存。 You should notice a difference in your install timings if you first do an "npm cache clean". 如果您第一次执行“npm cache clean”,您应该注意到安装时间的差异。 That will clean up anything not installed globally, for those you will have to explicitly do an "npm uninstall" 那将清理未全局安装的任何东西,对于那些你必须明确执行“npm uninstall”的人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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