A lightweight persistent in-memory cache library (v1.2.0) that extends node-cache with disk persistence and crash recovery. It periodically writes the full cache to disk and logs every write command in an append-only file, minimizing data loss on restart. Offers customizable serializers (default JSON) and automatic restoration on re-initialization. Compared to alternatives like persistent-cache, it provides far higher set throughput (623,668 ops/sec vs 550 ops/sec) while maintaining fast gets (21M+ ops/sec). Released on npm, actively maintained, ships TypeScript definitions.
npm install persistent-node-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage: create cache, set/get/delete keys, automatic restore, and custom serializer example.
Remove any .recover() calls. The cache auto-restores when constructed with the same cacheName. If using custom dir, pass the same dir option.
If upgrading from v1.1.x, implement a custom serializer that matches the previous format, or migrate data by re-reading with old version and writing with new.
Initialize cache with the same cacheName and dir options; recovery happens automatically. Do not call .recover().
Increase period to a higher value (e.g., 5000 ms) if write throughput is critical. Alternatively, set period to 0 to disable periodic full dumps (only append-only log is used).
Use distinct cacheName values for different logical caches. Do not share cacheName across separate instances.
Run 'npm install persistent-node-cache'. Ensure TypeScript version is >=3.8 if using ESM imports, and that 'esModuleInterop' is not required for named imports.
Remove .recover() calls. Recovery happens automatically on construction (v1.2.0+).
Ensure the directory path exists and the process has write permissions. Use an absolute path or create the directory before initializing cache.
Use the exact same cacheName and dir options both when creating and re-initializing the cache. For v1.2.0+, ensure automatic recovery is not overridden.