Registry / storage / cacache

cacache

JSON →
library21.0.0jsnpmunverified

cacache is a Node.js library for managing local key and content address caches. It is fast, fault-tolerant, cross-platform, and guarantees no corrupted data even if cache files are manipulated. Current stable version is 21.0.0 (requires Node ^22.22.2 || ^24.15.0 || >=26.0.0). It supports Subresource Integrity, automatic deduplication, streaming, and concurrency without locks. Used as npm's local cache but can be used standalone. Differentiators include performance, fault tolerance, and multi-hash support.

npm install cacache
INSTALL
IMPORT
SIG · CACACHE
C
cacache
storagejavascriptv21.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cacache
const cacache = require('cacache')
import cacache from 'cacache'
cacache is CJS-only; ESM import may fail without bundler handling.
get
const { get } = require('cacache')
const { get } = require('cacache/get')
Named exports are available via destructuring from the main module.
put
const { put } = require('cacache')
const put = require('cacache/put')
Only import from 'cacache' entry point.

Shows basic put/get operations with the cache, returning integrity hash.

const cacache = require('cacache'); const cachePath = '/tmp/my-cache'; const key = 'unique-key'; // Write data to cache cacache.put(cachePath, key, 'hello world').then((integrity) => { console.log('Cached with integrity:', integrity); // Read data back return cacache.get(cachePath, key); }).then((data) => { console.log('Retrieved:', data.toString()); }).catch(console.error);
Debug
Known issues
breakingVersion 21.0.0 drops support for Node <22.22.2. Older Node versions will fail to install.
fix
Upgrade Node to ^22.22.2 || ^24.15.0 || >=26.0.0
affects: >=21.0.0
gotchaThe cachePath must be a directory. Passing a file path will cause EEXIST or ENOTDIR errors.
fix
Ensure the target path is a directory (use mkdirp if necessary).
affects: >=1.0.0
gotchaThe key parameter in put/get is a string; passing a Buffer or object may lead to unexpected behavior.
fix
Always convert keys to strings (e.g., key.toString()).
affects: >=1.0.0
deprecatedThe 'tmp' utilities (mkdir, withTmp) are deprecated as of v12 and may be removed.
fix
Use your own temporary file utilities (e.g., tmp-promise).
affects: >=12.0.0
Errors
Common errors & fixes
Error: cache path is not a directory
The cachePath argument points to an existing non-directory or does not exist.
fix
Ensure the directory exists: `mkdir -p /tmp/my-cache` or use fs.mkdirSync with recursive: true.
TypeError: The "path" argument must be of type string. Received undefined
Missing cachePath argument in cacache.put() or cacache.get().
fix
Provide a valid string path as the first argument.
integrity verification failed
Data in cache has been corrupted or tampered with.
fix
Use cacache.verify() to clean up corrupted entries, or delete the cache directory and start fresh.
Upgrade
Version history
21.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
33 hits · last 30 days
node
30
Resources
cacache — npm install cacache · libregistry