Registry / storage / sync-disk-cache

sync-disk-cache

JSON →
library2.1.0jsnpmunverified

A synchronous disk-based cache library for Node.js (v2.1.0, last updated in 2018). It stores cached values as files in a temporary directory (defaulting to TMPDIR/<username>). Supports optional gzip/deflate compression. Primarily used in build toolchains (e.g., Ember CLI) for caching intermediate results. Unlike its async sibling (async-disk-cache), this library uses blocking I/O, making it unsuitable for production servers but convenient for scripts and build tools.

npm install sync-disk-cache
INSTALL
IMPORT
SIG · SYNC-DISK-CACHE
S
sync-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.

Cache
const Cache = require('sync-disk-cache');
import Cache from 'sync-disk-cache';
The package is CommonJS-only and does not ship ESM. Use require() in Node.js.
default export
const Cache = require('sync-disk-cache');
const { SyncDiskCache } = require('sync-disk-cache');
The module exports a single constructor function directly, not a named object.

Demonstrates basic usage: creating a cache instance, checking, getting, setting, removing, and clearing cached entries.

const Cache = require('sync-disk-cache'); const cache = new Cache('my-cache'); // Check existence const has = cache.has('testKey'); // Get a value const result = cache.get('testKey'); if (!result.isCached) { // Set a value cache.set('testKey', 'my cached data'); } // Remove a key cache.remove('testKey'); // Clear all entries cache.clear();
Debug
Known issues
deprecatedNode.js 8 and 10 are end-of-life; the package's engines field declares support for Node 8.* and >=10.*, but newer Node versions may have compatibility issues.
fix
Consider migrating to an async alternative like async-disk-cache or a more modern caching library.
affects: >=2.0.0
gotchaAll stored values become strings. Objects are not automatically serialized.
fix
Use JSON.stringify() before storing and JSON.parse() when retrieving if you need to cache objects.
affects: >=1.0.0
gotchaCompression is not available on Node.js 0.10.x because synchronous zlib methods are unsupported.
fix
Only use compression options (gzip, deflate, deflateRaw) on Node.js >=0.12.
affects: <2.0.0
gotchaTemporary directory can grow unbounded if OS cleanup mechanisms are not configured.
fix
Set $TMPDIR to a project-specific path and manually purge it, or rely on OS tmpwatch/tmpreaper.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'sync-disk-cache'
The package is not installed.
fix
Run `npm install sync-disk-cache` in your project directory.
TypeError: cache.get(...).content is undefined
Attempting to access .content on a cache miss result.
fix
Check isCached property first: if (result.isCached) { use result.content } else { handle miss }
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
28 hits · last 30 days
node
24
Amazon
1
OpenAI (training)
1
Resources
sync-disk-cache — npm install sync-disk-cache · libregistry