A Node.js disk-based cache module that writes cached items as files and manages automatic pruning of expired entries. Version 1.0.5 is the latest stable; it is a small utility with minimal dependencies (none notable). Key differentiator: it stores data on disk (file-based) with TTL expiry, automatically prunes expired items, and returns buffers with metadata (key, ttl, expires, parse method). It is useful for caching in environments with limited memory or when persistence across restarts is desired. The package supports both synchronous and asynchronous operations (getAll is async). It has not seen updates since 2022, suggesting maintenance mode.
npm install ttl-file-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows instantiation, set, get with buffer and parse, del, clear, and async getAll.
Use if (buf) { buf.parse(); } else { /* handle miss */ }Use with caution; consider pagination or a scan alternative if performance is critical.
Avoid using in latency-sensitive or high-concurrency scenarios. Consider an async file cache library instead.
Pass a custom dir option to the constructor: new Cache({ dir: '/persistent/path' })If you need only the raw buffer, use buf.slice(0) or convert via buf.toString('utf8') for string data.Always check if cache.get() returns a value: const buf = cache.get('key'); if (buf) { buf.parse(); }Ensure the dir exists before creating Cache instance, or use the default (created automatically if parent exists).
Convert complex objects to JSON strings or Buffers before caching.
Avoid getAll() on large caches; consider using get() with known keys or implementing pagination.
No dependency data recorded yet.