Registry / storage / lru-native2

lru-native2

JSON →
library1.2.6jsnpmunverified

An in-memory LRU cache for Node.js implemented in C++11 using std::unordered_map and std::list, offering high performance for large caches. Version 1.2.6 supports Node 14/16 on OSX and Linux. It is an alternative to node-lru-cache for very large hashes, avoiding V8 object overhead. Last updated in 2021, it is in maintenance mode with no recent releases.

npm install lru-native2
INSTALL
IMPORT
SIG · LRU-NATIVE2
L
lru-native2
storagejavascriptv1.2.6
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.

LRUCache
import LRUCache from 'lru-native2'
const LRUCache = require('lru-native2').LRUCache
Default export is the constructor. TypeScript types are included.
LRUCache (CommonJS)
const LRUCache = require('lru-native2')
const { LRUCache } = require('lru-native2')
CommonJS users should use require without destructuring; the module exports a single constructor.
LRUCache (TypeScript)
import LRUCache from 'lru-native2'
import { LRUCache } from 'lru-native2'
TypeScript types are bundled; the default import is the constructor class.

Shows instantiation with options, set/get, size, remove, clear, and stats.

import LRUCache from 'lru-native2'; const cache = new LRUCache({ maxElements: 1000, maxAge: 60000 }); cache.set('key1', 'value1'); cache.set('key2', 'value2'); console.log(cache.get('key1')); // 'value1' console.log(cache.size()); // 2 cache.remove('key2'); console.log(cache.get('key2')); // undefined cache.clear(); console.log(cache.size()); // 0 const stats = cache.stats(); console.log('Stats:', stats);
Debug
Known issues
deprecatedPackage is deprecated. No updates since 2021. Use 'lru-cache' or other maintained alternatives.
fix
Migrate to 'lru-cache' (npm package) or 'quick-lru'.
affects: >=1.0.0
breakingNative addon requires build tools. Installation may fail without node-gyp or on unsupported platforms.
fix
Ensure build-essential tools are installed (e.g., 'apt install build-essential' on Ubuntu).
affects: >=1.0.0
gotchaKey must be a string; using non-string keys may cause unexpected behavior.
fix
Always use strings for keys. Coerce keys with String(key) if needed.
affects: >=0.1.0
gotchamaxElements option default is 0, meaning no limit, not 0 items. Setting maxElements: 0 disables eviction.
fix
Explicitly set maxElements to a positive integer for bounded cache.
affects: >=0.1.0
Errors
Common errors & fixes
Error: 'node-gyp' is not recognized as an internal or external command
node-gyp is missing during npm install of native module.
fix
Run 'npm install -g node-gyp' and ensure build tools are installed (e.g., 'apt install build-essential' or 'xcode-select --install' on macOS).
gyp: Undefined variable 'OS'
Incompatible node-gyp version or mismatched Python version.
fix
Use node-gyp v8.x and Python 3.6+; see node-gyp documentation.
Module did not self-register: '.../lru-native2.node'.
The native binary was built for a different Node.js version or architecture.
fix
Recompile the module: run 'npm rebuild lru-native2' or 'node-gyp rebuild'.
Upgrade
Version history
1.2.6latest on npm
Audit
Dependencies
node-gyprequiredBuild tool for native addons, required to compile the C++ code during npm install.
Agent activity
23 hits · last 30 days
node
22
OpenAI (training)
1
Resources
lru-native2 — npm install lru-native2 · libregistry