A lightweight promise-based caching library for JavaScript and TypeScript (v2.0.0, actively maintained). It caches asynchronous promises and synchronous values, eliminating redundant requests and preventing race conditions. Features include TTL expiry, LRU eviction for bounded caches, automatic cleanup of expired entries, and pending promise protection (unresolved promises are never evicted). Differentiators: promise-aware (stores pending promises), supports both async and sync values, bounded cache with LRU, and TypeScript-first with built-in types. Released monthly on npm.
npm install promise-cachexNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage: create a cache with 5s TTL and 2s cleanup interval, then fetch and cache a promise.
Use `ttl` and `cleanupInterval` options. See README for new option names.
Pass a synchronous factory function or static value as the second argument to `cache.get`.
Ensure promises resolve in a timely manner or increase `maxEntries` to accommodate potential overflow.
Set TTL to a positive number for auto-expiry, or use `maxEntries` for bounded cache.
Use `cache.size()` synchronously in v2. If migrating from v1, remove any `await`.
Use `const { PromiseCacheX } = require('promise-cachex');`Run `npm install promise-cachex` and ensure package.json contains the dependency.
Ensure `cache` is an instance of `PromiseCacheX` and imported correctly.
No dependency data recorded yet.