Registry / storage / cache-manager-fs-binary

cache-manager-fs-binary

JSON →
library1.0.4jsnpmunverified

A filesystem store for node-cache-manager that stores binary data as separate files, returning them as readable streams or buffers. Version 1.0.4 is the latest stable release. It supports limiting disk space, refilling cache on restart, and storing buffers either as separate files or within the JSON cache file. Designed for caching binary data like images with streaming support via response piping. Suitable for Node.js 4, 5, and iojs.

npm install cache-manager-fs-binary
INSTALL
IMPORT
SIG · CACHE-MANAGER-FS-B
C
cache-manager-fs-binary
storagejavascriptv1.0.4
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
import fsStore from 'cache-manager-fs-binary'
const fsStore = require('cache-manager-fs-binary')
Package is CommonJS only; import syntax may require a bundler or ESM wrapper. Use require or dynamic import.
fsStore (via require)
const fsStore = require('cache-manager-fs-binary');
import { fsStore } from 'cache-manager-fs-binary'
The package exports a single function; named import does not work.
caching (from cache-manager)
import { caching } from 'cache-manager';
const caching = require('cache-manager').caching;
Both work; prefer import for ES modules. cache-manager v3+ uses named exports.

Shows how to create a filesystem cache with binary stream support, wrap a cache miss function, and handle the resulting stream.

const cacheManager = require('cache-manager'); const fsStore = require('cache-manager-fs-binary'); const diskCache = cacheManager.caching({ store: fsStore, options: { reviveBuffers: true, binaryAsStream: true, ttl: 60 * 60, maxsize: 1000 * 1000 * 1000, path: 'diskcache', preventfill: true } }); const cacheKey = 'myImage'; diskCache.wrap(cacheKey, function(cacheCallback) { const image = Buffer.from('mock-image-data'); cacheCallback(null, { binary: { image: image } }); }, { ttl: 60 * 60 }, function(err, result) { if (err) console.error(err); else { const stream = result.binary.image; // stream.pipe(res) for HTTP response } });
Debug
Known issues
gotchaValues under the 'binary' key are stored as separate files and are replaced with streams or buffers. This changes the original object structure.
fix
Ensure your callback handles the modified object; use binaryAsStream option to control stream vs buffer.
affects: >=1.0.0
gotchaTTL is in seconds, not milliseconds. Common mistake from other cache libraries.
fix
Set ttl in seconds, e.g., 3600 for one hour.
affects: >=1.0.0
gotchaThe 'path' option is relative to process.cwd() by default. May cause unexpected disk usage if not absolute.
fix
Use an absolute path or ensure the working directory is correct.
affects: >=1.0.0
gotchaCache keys used in 'binary' object become filenames; invalid filesystem characters cause errors.
fix
Sanitize keys to avoid characters like /, :, *, etc.
affects: >=1.0.0
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, open '...'
The cache directory specified in 'path' does not exist.
fix
Create the directory before caching, or set 'preventfill: true' and ensure path exists.
TypeError: Cannot read property 'pipe' of undefined
The 'binary' key is missing or not a stream when binaryAsStream is true.
fix
Ensure your cached object has a 'binary' property with a Buffer. Check if TTL expired and re-fetch.
RangeError: Maximum call stack size exceeded
Circular reference in cached object; JSON.stringify fails.
fix
Avoid circular structures; cache only plain JSON-serializable data under non-binary keys.
Warning: Possible EventEmitter memory leak detected. 11 listeners added...
Multiple concurrent wrap calls may cause event listener buildup.
fix
Increase event listener limit or ensure callbacks are registered properly. Consider using 'multicache' to limit concurrent operations.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
cache-managerrequiredRequired as the caching framework.
Agent activity
34 hits · last 30 days
node
30
OpenAI (training)
1
Resources
cache-manager-fs-binary — npm install cache-manager-fs-binary · libregistry