Clean Cache is a minimal in-memory JavaScript cache with TTL (time-to-live) support, packaged as a single file with zero dependencies. Current stable version is 1.0.2. It offers a simple API with `add`, `retrieve`, `count`, and `tidy` methods, and validates keys to prevent null/undefined. Unlike larger caching libraries (e.g., node-cache, lru-cache), it keeps dependencies to a minimum and is fully tested. Suitable for small Node.js projects needing a lightweight, ephemeral cache.
npm install clean-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Basic usage: create a cache with TTL, add and retrieve an item, then see it expire.
Always provide a valid string or number key.
Use milliseconds. e.g., 5000 for 5 seconds.
Use require or use a bundler that handles CJS.
Check for null explicitly.
Call myCache.tidy() periodically to free memory.
To avoid unintended expiration, pass a very large number or rely on default behavior.
Use named import: `const { Cache } = require('clean-cache')`Always check for null: `const val = myCache.retrieve('key'); if (val !== null) { ... }`Pass a valid string or number. Example: `myCache.add('validKey', data)`Use `const { Cache } = require('clean-cache')`No dependency data recorded yet.