Simple in-memory cache with TTL and capacity for JavaScript. Version 1.3.1 is the current stable release, with infrequent updates. It provides a lightweight cache with optional time-to-live per entry, capacity-limited eviction, and events for put, del, drop, hit, and miss. Differentiates from similar libraries (e.g., node-cache) by its simple API and event-driven architecture. Designed for Node.js environments, with no external dependencies.
npm install ttlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a cache with TTL and capacity, listens to events, and demonstrates put/get with expiry.
Use strings or primitives as keys; if using objects, ensure same reference.
Understand eviction policy: oldest inserted items are dropped when capacity is exceeded.
Pass numbers in milliseconds (e.g., 5000 for 5 seconds).
Install @types/ttl or declare module manually.
Use const Cache = require('ttl'); in CommonJS or import Cache from 'ttl'; in ESM.Use import Cache from 'ttl'; instead of require.
Run npm install ttl --save.
Use const cache = new Cache({ ... }); with the 'new' keyword.No dependency data recorded yet.