选择命令行版本:
🌐 Synopsis
npm cache add <package-spec>npm cache clean [<key>]npm cache ls [<name>@<version>]npm cache verify
注意:此命令不支持工作区。
🌐 Note: This command is unaware of workspaces.
🌐 Description
用于添加、列出或清理 npm 缓存文件夹。
🌐 Used to add, list, or clean the npm cache folder.
🌐 Details
npm 会将缓存数据存储在配置的 cache 中的一个不透明目录中,名为 _cacache。该目录是一个基于 cacache 的内容可寻址缓存,用于存储所有 HTTP 请求数据以及其他与包相关的数据。这个目录主要通过 pacote 访问,pacote 是在 npm@5 中负责所有包获取的库。
🌐 npm stores cache data in an opaque directory within the configured cache, named _cacache. This directory is a cacache-based content-addressable cache that stores all http request data as well as other package-related data. This directory is primarily accessed through pacote, the library responsible for all package fetching as of npm@5.
所有通过缓存的数据在插入和提取时都会进行完整性验证。缓存损坏将触发错误,或者向 pacote 发出信号,指示必须重新获取数据,且它会自动执行此操作。因此,除了回收磁盘空间外,通常不需要清除缓存,这也是为什么 clean 现在需要 --force 运行的原因。
🌐 All data that passes through the cache is fully verified for integrity on both insertion and extraction. Cache corruption will either trigger an error, or signal to pacote that the data must be refetched, which it will do automatically. For this reason, it should never be necessary to clear the cache for any reason other than reclaiming disk space, thus why clean now requires --force to run.
目前没有通过 npm 提供的方法来检查或直接管理此缓存的内容。要访问它,必须直接使用 cacache。
🌐 There is currently no method exposed through npm to inspect or directly manage the contents of this cache. In order to access it, cacache must be used directly.
npm 本身不会删除数据:随着新包的安装,缓存会逐渐增大。
🌐 npm will not remove data by itself: the cache will grow as new packages are installed.
🌐 A note about the cache's design
npm 缓存严格来说只是一个缓存:不应依赖它作为包数据的持久可靠存储。npm 不保证之前缓存的数据之后一定可用,并会自动删除损坏的内容。缓存的主要保证是,如果它返回数据,则该数据将与插入的数据完全一致。
🌐 The npm cache is strictly a cache: it should not be relied upon as a persistent and reliable data store for package data. npm makes no guarantee that a previously-cached piece of data will be available later, and will automatically delete corrupted contents. The primary guarantee that the cache makes is that, if it does return data, that data will be exactly the data that was inserted.
要对现有缓存内容进行离线验证,请使用 npm cache verify。
🌐 To run an offline verification of existing cache contents, use npm cache verify.
🌐 Configuration
cache%LocalAppData%\npm-cache,Posix: ~/.npmnpm 的缓存目录的位置。
🌐 The location of npm's cache directory.
🌐 See Also