Two-level cache for Node.js (in-memory + Redis) with automatic serialization, jitter, double-checked locking to prevent cache stampedes and thundering herds. Version 3.7.0 released under MIT license with monthly releases. Key differentiators: built-in distributed mutex and semaphore primitives, jittered TTLs (default 30-60s Redis, 2-5s in-memory), and double-checked locking on cache miss functions. ESM-only since v3.0.0.
npm install petty-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows creation of PettyCache client with environment-based Redis config, and usage of fetch() with a cache miss function.
Use import PettyCache from 'petty-cache' instead of require().
Use new PettyCache({ host, port }) or pass the RedisClient directly.Ensure your cache miss function properly serializes complex objects if needed. PettyCache automatically serializes/deserializes, but custom serialization may be required for non-JSON-safe types.
Change to import PettyCache from 'petty-cache' and ensure your project is ESM-enabled (add type: 'module' to package.json).
Ensure tsconfig.json has 'esModuleInterop': true and use 'import PettyCache from 'petty-cache''.
npm install redis (must be version >=2.6.0).