Registry / storage / async-disk-cache

async-disk-cache

JSON →
library2.1.0jsnpmunverified

Async disk cache library for Node.js (v2.1.0, stable, low maintenance). Stores cache entries as files in a temporary directory (default $TMPDIR/<username>). Provides promise-based async API with compression support (gzip, deflate, deflateRaw) and optional buffer support. Differentiated from sync-disk-cache by async operations; a lightweight alternative to full-featured caching solutions like node-cache-manager. No external dependencies. Actively used in Ember CLI ecosystem.

npm install async-disk-cache
INSTALL
IMPORT
SIG · ASYNC-DISK-CACHE
A
async-disk-cache
storagejavascriptv2.1.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.

default
const Cache = require('async-disk-cache');
import Cache from 'async-disk-cache';
This package is CommonJS-only; no ESM exports are provided.
Cache constructor
const cache = new Cache('my-cache');
const cache = new Cache();
A cache key (string) is required as the first argument; omitting it will cause a runtime error.
options (compression)
const cache = new Cache('my-cache', { compression: 'gzip' });
const cache = new Cache('my-cache', { compression: true });
Compression must be a string ('gzip', 'deflate', 'deflateRaw'), not a boolean.

Demonstrates basic usage: create a cache, set a value, get it, remove it, and clear all.

const Cache = require('async-disk-cache'); const cache = new Cache('my-cache'); // Set a value cache.set('key1', 'hello world').then(() => { // Get the value return cache.get('key1'); }).then(entry => { console.log(entry.isCached); // true console.log(entry.value); // 'hello world' // Remove the entry return cache.remove('key1'); }).then(() => { return cache.get('key1'); }).then(entry => { console.log(entry.isCached); // false // Clear entire cache return cache.clear(); }).catch(err => { console.error(err); });
Debug
Known issues
gotchaCache key must be a string; non-string keys will cause errors or unexpected behavior.
fix
Always pass a string as the first argument to the constructor.
affects: >=0.0.0
gotchaThe cache stores files in the system temp directory ($TMPDIR) by default. If temp cleaning is not configured, disk usage can grow unbounded.
fix
Set $TMPDIR to a project-specific path and manually purge old entries, or rely on OS temp cleanup (e.g., tmpreaper on Linux, periodic tasks on macOS).
affects: >=0.0.0
deprecatedThe 'supportBuffer' option is available but may be undocumented or unstable in some versions.
fix
Test buffer support with your specific version; consider not using it if not needed.
affects: >=2.0.0
gotchaCompression option must be exactly one of 'gzip', 'deflate', or 'deflateRaw'. Using an invalid value will not compress and may not error.
fix
Validate compression string against the allowed values.
affects: >=0.0.0
gotchaCache get returns an object with 'isCached' boolean, not the value directly. Common mistake: expecting the value from get().
fix
Access the value via the returned object's 'value' property.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Class constructor Cache cannot be invoked without 'new'
Trying to instantiate Cache without 'new' keyword
fix
Use 'new Cache(key, options)'
TypeError: cache.get is not a function
Importing the package incorrectly (e.g., as default export in ESM)
fix
Use require('async-disk-cache') as CommonJS; this package does not support ESM imports.
Error: ENOENT: no such file or directory, open '...'
The temp directory does not exist or is not writable
fix
Ensure $TMPDIR is set and the directory exists; use an absolute path if custom.
Error: The "path" argument must be of type string. Received undefined
Cache constructor called without key argument
fix
Pass a string as the first argument to new Cache('my-cache')
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
39 hits · last 30 days
node
34
Resources
async-disk-cache — npm install async-disk-cache · libregistry