【问题标题】:Does npm cache packages?npm 缓存包吗?
【发布时间】:2018-01-16 04:48:36
【问题描述】:

在我的服务器中,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 后,run npm install 在 171.389 秒内添加了 1551 个包。然后rm -rf node_modules && npm install 在 152.378 秒内添加了 1551 个包。 npm 真的使用缓存吗?

【问题讨论】:

    标签: node.js npm npm-install


    【解决方案1】:

    默认使用全局包缓存。如果您首先执行“npm cache clean”,您应该会注意到安装时间的不同。这将清理任何未全局安装的东西,对于那些你必须明确执行“npm卸载”的人

    【讨论】:

    • 在运行 rm -rf node_modules && npm clean cache --force 之后,再运行 npm install 在 171.389 秒内添加了 1551 个包。然后rm -rf node_modules && npm install 在 152.378 秒内添加了 1551 个包。 npm 真的使用缓存吗?
    • 请确认“npm cache clean --force”实际上正在清除您的全局缓存。在windows中,c:/users/username/AppData/Roaming/npm
    • 我不明白 npm cache clean 是什么意思。这将清理任何未全局安装的东西,对于那些你必须明确执行“npm卸载”的人,但我在运行npm cache clean --force之前检查了%USERPROFILE%\AppData\Roaming\npm-cache文件夹的大小,并在运行它之后查看它肯定删除了很多数据(缓存)。我知道答案应该是,对于那些你必须明确地做一个npm -g uninstall
    • 这是一个公平的观点。缓存清理不会卸载全局或其他已安装的软件包。它将做的是从位于 Windows 环境中上述漫游文件夹中的全局缓存中删除缓存的包
    猜你喜欢
    • 2019-10-08
    • 2018-09-30
    • 1970-01-01
    • 2022-11-05
    • 2017-02-09
    • 2021-05-16
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    相关资源
    最近更新 更多