A filesystem-based caching library for JavaScript/TypeScript functions. Current stable version is 3.4.0, with a release cadence of roughly yearly major versions. It persists function results between restarts, supports waiting for in-progress results, works across workers, and allows custom serialization/deserialization. Unlike in-memory caches, it survives process restarts and can be shared among workers. It is ESM-only and ships TypeScript definitions.
npm install with-file-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage: creates a file-cached function that caches results based on the argument string. Second call with same argument hits cache.
Configure a custom cache directory using the cacheDir option in withFileCache.
Use Node 16+ and ensure your project is ESM (type: 'module' in package.json) or use dynamic import.
Provide serialize and deserialize options to handle complex data types.
Combine arguments into a single unique string or object in calcCacheKey.
Update baseKey to return a string (or a promise of string) to represent a base cache key.
Change to: import { withFileCache } from 'with-file-cache'Call withFileCache({ baseKey: ... }) with at least baseKey provided.Switch to ESM by adding 'type': 'module' in package.json, or use dynamic import() with await.
Provide calcCacheKey as a function that returns a cache key based on arguments.