Simple LRU (Least Recently Used) cache module for Node.js. Current version 1.1.1 provides a hash-map-backed LRU cache with automatic eviction of least recently used items when max key count or byte size is exceeded. Supports optional item expiration (TTL), custom metadata, event listeners for evictions, and stats tracking. Implemented with a double-linked list for efficient LRU ordering. No external dependencies. Suitable for scenarios requiring a lightweight, predictable caching solution with configurable limits based on item count or byte size. Lower-level and less feature-rich than alternatives like lru-cache, but has zero dependencies and straightforward API.
npm install pixl-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates LRU cache with maxItems and shows basic operations: set, get, overflow eviction, delete, clear. Also demonstrates byte limit and TTL configuration.
Account for string byte size as 2x character count when using maxBytes limit.
Use cache.on('expire', ...) instead of cache.on('evict', ...).Deep clone objects before storing if mutation after set() is a concern.
Use manual get-and-set pattern to refresh TTL if needed: cache.set(key, cache.get(key)).
Consider key length overhead when setting maxBytes. Use short keys to conserve space.
Use require('pixl-cache') or use dynamic import().default for ESM wrappers.Use createRequire from 'module' or switch to const LRU = (await import('pixl-cache')).default;Ensure LRU is properly instantiated: const cache = new LRU(options);
Check version - pixl-cache 1.x has .on() method. Upgrade if using ancient version.
No dependency data recorded yet.