Registry / storage / node-cache-engine

node-cache-engine

JSON →
library2.0.3jsnpmunverified

High-performance caching library for Node.js and browser environments supporting LRU and LFU eviction policies with O(1) complexity for all operations. Version 2.0.3 requires Node >=18.18.2. Ships TypeScript definitions. Differentiates from other caches by supporting both LRU and LFU engines, custom hash tables via symbols, and a unified API with clearAll and toArray methods for LRU. Offers configurable maximum size. Actively maintained with regular releases.

npm install node-cache-engine
INSTALL
IMPORT
SIG · NODE-CACHE-ENGINE
N
node-cache-engine
storagejavascriptv2.0.3
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.

createCache
import { createCache } from 'node-cache-engine'
const createCache = require('node-cache-engine').createCache
Always use named import. CommonJS require works but default is ESM.
LRU engine
const cache = createCache({ engine: 'LRU' })
import { LRU } from 'node-cache-engine'
Set engine via option string, not imported class.
LFU engine
const cache = createCache({ engine: 'LFU' })
const cache = createCache({ engine: 'lfu' })
Engine key is uppercase: 'LRU' or 'LFU'.

Shows creating a cache instance, adding, getting, checking, removing, and iterating items.

import { createCache } from 'node-cache-engine'; const cache = createCache({ size: 100, engine: 'LRU' }); cache.add('user:123', { name: 'Alice' }); const user = cache.get('user:123'); if (cache.has('user:123')) { cache.remove('user:123'); } console.log(cache.size()); // 0 cache.add('a', 1); console.log(cache.toArray()); // [['a', 1]]
Debug
Known issues
breakingNode.js version requirement was raised to >=18.18.2 in v2.0.0.
fix
Upgrade Node.js to >=18.18.2 or pin version to 1.x.
affects: >=2.0.0
gotchaThe default maximum size is Number.MAX_SAFE_INTEGER, which may cause memory issues if not limited.
fix
Always provide an explicit size option to avoid unbounded growth.
affects: >=1.0.0
deprecatedCustom hash table must implement symbols from package; internal structure may change in minor versions.
fix
Use default hash table unless you have extreme performance needs >5M entries.
affects: >=2.0.0
gotchaEngine option is case-sensitive: 'LRU' or 'LFU'. Lowercase will treat as invalid and may default silently.
fix
Ensure engine string is uppercase: 'LRU' or 'LFU'.
affects: >=1.0.0
gotchaclearAll() and toArray() are only available on LRU engine, not LFU.
fix
Use LRU if you need those methods, or implement your own iteration for LFU.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: createCache is not a function
Importing default instead of named export in ESM.
fix
import { createCache } from 'node-cache-engine'
Error: engine must be LRU, LFU or custom
Engine option passed as lowercase or misspelled.
fix
Use engine: 'LRU' or engine: 'LFU' exactly.
TypeError: cache.clearAll is not a function
Using LFU engine which does not have clearAll method.
fix
Use LRU engine, or manually remove items by iterating keys.
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using CommonJS require with newer versions that are ESM-only.
fix
Use import statement or dynamic import().
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
Amazon
1
Resources
node-cache-engine — npm install node-cache-engine · libregistry