什么时候使用npm缓存?

时间:2013-12-30 08:58:42

标签: node.js npm

我何时必须使用npm cache clean? 而且,为什么在使用npm cache clean之后我会得到info trying

info trying registry request attempt 1 at 09:54:07

http GET https://registry.npmjs.org/delayed-stream/latest
http 304 https://registry.npmjs.org/delayed-stream/latest

1 个答案:

答案 0 :(得分:11)

Npm将软件包缓存到目录(Linux / OS X上的~/.npm和Windows上的%AppData%/npm-cache)。

当您有多个基于nodejs的设置需要各种包作为依赖项时,这会有所帮助。 Npm不会下载已经在缓存中的软件包,而是使用缓存中的软件包(如果它已经存在)。因此,在这种情况下,它会尝试优化它必须执行的下载次数。

现在,您何时使用npm cache clean。我出于某种原因使用它时,我的缓存因不同依赖项的某些冲突版本而被破坏,或者您只是想清理您根本不需要的软件包,例如某些依赖项的旧版本。

基本上,在使用npm cache clean之后,就像全局安装了节点模块一样全新安装了nodejs / npm(除非你用npm uninstall命令删除它们,否则它们会保留到你之前) 。

其他信息:https://docs.npmjs.com/cli/cache#configuration