Registry / storage / simple.cache

simple.cache

JSON →
library2.0.4jsnpmunverified

A minimal LRU (Least Recently Used) in-memory cache for Node.js, version 2.0.4. This package provides a straightforward caching solution with configurable maximum size (default 1000) and essential operations: set, get, has, remove, size, clear, keys, and dump. It ships with TypeScript type definitions, supports Node.js >=12, and uses the standard LRU algorithm by Dominic Tarr. Lightweight with no external dependencies.

npm install simple.cache
INSTALL
IMPORT
SIG · SIMPLE.CACHE
S
simple.cache
storagejavascriptv2.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SimpleCache
✓ import SimpleCache from 'simple.cache'
✗ const SimpleCache = require('simple.cache')
ESM import since version 2.0.0; CommonJS require still works but prefer ESM for compatibility with modern Node.js.
SimpleCache
✓ import SimpleCache from 'simple.cache'
✗ import { SimpleCache } from 'simple.cache'
This package has a default export, not named export. Using named import will result in undefined.
SimpleCache instance
✓ const cache = SimpleCache(500)
✗ const cache = new SimpleCache(500)
SimpleCache is a factory function, not a constructor. Do not use 'new'.

Shows creating an LRU cache with max size, basic operations (set, get, has, remove, size, keys, dump, clear), and LRU eviction behavior.

import SimpleCache from 'simple.cache'; const cache = SimpleCache(3); // max 3 entries cache.set('a', 1); cache.set('b', 2); cache.set('c', 3); cache.get('b'); // 2 cache.set('d', 4); // evicts 'a' (LRU) cache.has('a'); // false cache.size(); // 3 cache.keys(); // ['b', 'c', 'd'] cache.remove('c'); cache.dump(); // { b: 2, d: 4 } cache.clear(); console.log('Done');
Debug
Known issues
breakingIn version 2.0.0, the package switched from CommonJS to native ESM. If you use require(), your code may break if the consuming project is set to type: 'module'.
fix
Use import SimpleCache from 'simple.cache' instead of require('simple.cache').
affects: >=2.0.0
gotchaSimpleCache is a factory function, not a class. Using 'new SimpleCache()' will throw a TypeError.
fix
Call SimpleCache(max) directly without 'new'.
affects: >=1.0.0
gotchaThe 'set' method does not return any value; attempting to use the return value (e.g., chaining) will give undefined.
fix
Do not expect a return from set(); it simply adds/updates the entry.
affects: >=1.0.0
gotchaThe 'max' parameter must be a positive integer. Passing 0 or negative may result in unexpected behavior.
fix
Always pass a positive integer to SimpleCache(max).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: SimpleCache is not a constructor
Using 'new SimpleCache()' assuming it's a class.
fix
Use 'const cache = SimpleCache(100)' without 'new'.
Cannot find module 'simple.cache'
Package not installed or wrong import syntax.
fix
Run 'npm install simple.cache' and use correct import: 'import SimpleCache from 'simple.cache''.
Uncaught SyntaxError: The requested module 'simple.cache' does not provide an export named 'default'
Using an older version that does not support ESM or incorrect import syntax.
fix
Ensure you have version 2.x or use CommonJS: 'const SimpleCache = require('simple.cache')'.
Upgrade
Version history
2.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
Resources
simple.cache — npm install simple.cache · libregistry