Registry / database / simple-lru-cache

simple-lru-cache

JSON →
library0.0.2jsnpmunverified

The `simple-lru-cache` package offers a minimalistic and fast Least Recently Used (LRU) cache implementation for Node.js. Its core functionality revolves around prioritizing recently accessed keys, ejecting the least recently used key only when the cache reaches its configured maximum size (`maxSize`). Despite its explicit goal of simplicity and speed, the package is currently at version 0.0.2 and has not seen updates for over eight years, indicating it is abandoned. This makes it unsuitable for modern production environments due to potential security vulnerabilities, lack of compatibility with newer Node.js versions, and absence of modern features like time-based expiration (TTL). Its key differentiator was intended to be its extreme simplicity and speed compared to more feature-rich alternatives like `lru-cache`, but its current state makes it a significant risk. Developers should consider maintained alternatives or native JavaScript `Map` objects for simple caching needs.

npm install simple-lru-cache
INSTALL
IMPORT
SIG · SIMPLE-LRU-CACHE
S
simple-lru-cache
databasejavascriptv0.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

SimpleCache
var SimpleCache = require("simple-lru-cache")
import SimpleCache from 'simple-lru-cache'
This package is CommonJS-only and does not provide an ESM export. Direct ESM import will result in runtime errors.

Demonstrates basic cache initialization and common operations including setting, getting, deleting, and resetting entries.

var SimpleCache = require("simple-lru-cache"); // Initialize the cache with a maximum size of 1000 items var cache = new SimpleCache({"maxSize":1000}); // Add a key-value pair to the cache cache.set("hello","world"); // Retrieve a value by its key var value = cache.get("hello"); console.log(`Retrieved: ${value}`); // Output: Retrieved: world // Add more items to trigger LRU eviction if maxSize is reached for (let i = 0; i < 1001; i++) { cache.set(`key${i}`, `value${i}`); } // Delete a specific key from the cache cache.del("hello"); console.log(`'hello' after deletion: ${cache.get('hello')}`); // Output: 'hello' after deletion: undefined // Reset the entire cache, removing all entries cache.reset(); console.log(`Cache size after reset: ${cache.size()}`); // Output: Cache size after reset: 0
Debug
Known issues
breakingThis package is abandoned, with the last commit over 8 years ago. It is highly unrecommended for production use due to a complete lack of maintenance, potential security vulnerabilities, and likely incompatibility with modern Node.js versions and best practices.
fix
Migrate to an actively maintained LRU cache library such as 'lru-cache' or explore native JavaScript structures like `Map` for simple caching needs.
affects: >=0.0.2
gotchaThe package is strictly CommonJS-only and does not provide ESM exports. Attempting to `import` it in an ESM module will lead to runtime errors.
fix
Ensure you are using CommonJS `require()` syntax: `var SimpleCache = require("simple-lru-cache");`. For ESM projects, consider a modern cache library that supports ESM.
affects: >=0.0.2
gotchaThis cache implementation does not support time-to-live (TTL) for entries. Items are only evicted based on the Least Recently Used policy when the `maxSize` limit is exceeded.
fix
If time-based expiration is required, you must implement it externally or choose a different cache library that offers native TTL functionality.
affects: >=0.0.2
gotchaThe cache stores direct references to objects. Modifying an object retrieved from the cache will also modify the object within the cache itself. There is no automatic deep cloning.
fix
To maintain immutability, manually clone objects before storing them in the cache or after retrieving them, if modifications are intended.
affects: >=0.0.2
gotchaThe extremely low version (0.0.2) and long-term inactivity indicate that this library has not been robustly tested or evolved with community feedback, potentially containing unknown bugs or edge cases.
fix
Thoroughly test any usage, especially in performance-critical or high-concurrency scenarios. For reliability, prioritize libraries with greater maturity and active maintenance.
affects: >=0.0.2
Errors
Common errors & fixes
TypeError: simple_lru_cache__WEBPACK_IMPORTED_MODULE_0__ is not a constructor
Attempting to import `SimpleCache` using ES module syntax (`import`) in an environment where the package is only available as CommonJS.
fix
Use CommonJS `require` syntax instead: `var SimpleCache = require("simple-lru-cache");`
ReferenceError: SimpleCache is not defined
The `SimpleCache` class was not properly imported or required before being used to instantiate a cache.
fix
Ensure `var SimpleCache = require("simple-lru-cache");` is at the top of your script file before any usage of `SimpleCache`.
(No explicit error, but unexpected behavior where items don't disappear after a time limit)
Misunderstanding that `simple-lru-cache` only uses an LRU eviction policy and does not support time-to-live (TTL) for cache entries.
fix
Be aware that items are only removed when the cache's `maxSize` is reached and they are the least recently used. Implement external TTL logic if time-based expiration is necessary.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
10
Meta
2
Resources