Minimalistic library (v1.0.0, stable) that reads a file into memory and caches its contents, invalidating the cache when the file's modification time changes. Returns promises (async) and offers sync variants. No dependencies, ESM/CJS compatible. Key differentiator: automatic cache invalidation via stat() on every read, avoiding stale data without explicit TTL or watchers. Suitable for small config files or one-shot reads where performance is not critical.
npm install read-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows async file read with caching, retrieving cached content, and clearing the cache.
Use a persistent caching mechanism (e.g., redis, fs) if cross-process caching is needed.
If reading many files rapidly, use a dedicated cache with change detection (e.g., chokidar).
Always pass 'utf8' (or desired encoding) when expecting string output.
Use try-catch: try { const data = readCache.sync('path'); } catch (err) { ... }Ensure file mtime updates on content change, or call clear() after writes.
Use: import readCache from 'read-cache'; readCache.sync('file')Run: npm install read-cache
Use readCache (async) or readCache.sync for synchronous retrieval.
Check path or use try-catch with readCache.sync.
No dependency data recorded yet.