{"id":12030,"library":"simple-lru-cache","title":"Simple LRU Cache","description":"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.","status":"abandoned","version":"0.0.2","language":"javascript","source_language":"en","source_url":"http://github.com/geisbruch/node-simple-lru-cache","tags":["javascript","cache","lru","simple","fast"],"install":[{"cmd":"npm install simple-lru-cache","lang":"bash","label":"npm"},{"cmd":"yarn add simple-lru-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add simple-lru-cache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not provide an ESM export. Direct ESM import will result in runtime errors.","wrong":"import SimpleCache from 'simple-lru-cache'","symbol":"SimpleCache","correct":"var SimpleCache = require(\"simple-lru-cache\")"}],"quickstart":{"code":"var SimpleCache = require(\"simple-lru-cache\");\n\n// Initialize the cache with a maximum size of 1000 items\nvar cache = new SimpleCache({\"maxSize\":1000});\n\n// Add a key-value pair to the cache\ncache.set(\"hello\",\"world\");\n\n// Retrieve a value by its key\nvar value = cache.get(\"hello\");\nconsole.log(`Retrieved: ${value}`); // Output: Retrieved: world\n\n// Add more items to trigger LRU eviction if maxSize is reached\nfor (let i = 0; i < 1001; i++) {\n  cache.set(`key${i}`, `value${i}`);\n}\n\n// Delete a specific key from the cache\ncache.del(\"hello\");\nconsole.log(`'hello' after deletion: ${cache.get('hello')}`); // Output: 'hello' after deletion: undefined\n\n// Reset the entire cache, removing all entries\ncache.reset();\nconsole.log(`Cache size after reset: ${cache.size()}`); // Output: Cache size after reset: 0","lang":"javascript","description":"Demonstrates basic cache initialization and common operations including setting, getting, deleting, and resetting entries."},"warnings":[{"fix":"Migrate to an actively maintained LRU cache library such as 'lru-cache' or explore native JavaScript structures like `Map` for simple caching needs.","message":"This 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.","severity":"breaking","affected_versions":">=0.0.2"},{"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.","message":"The package is strictly CommonJS-only and does not provide ESM exports. Attempting to `import` it in an ESM module will lead to runtime errors.","severity":"gotcha","affected_versions":">=0.0.2"},{"fix":"If time-based expiration is required, you must implement it externally or choose a different cache library that offers native TTL functionality.","message":"This 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.","severity":"gotcha","affected_versions":">=0.0.2"},{"fix":"To maintain immutability, manually clone objects before storing them in the cache or after retrieving them, if modifications are intended.","message":"The 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.","severity":"gotcha","affected_versions":">=0.0.2"},{"fix":"Thoroughly test any usage, especially in performance-critical or high-concurrency scenarios. For reliability, prioritize libraries with greater maturity and active maintenance.","message":"The 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.","severity":"gotcha","affected_versions":">=0.0.2"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use CommonJS `require` syntax instead: `var SimpleCache = require(\"simple-lru-cache\");`","cause":"Attempting to import `SimpleCache` using ES module syntax (`import`) in an environment where the package is only available as CommonJS.","error":"TypeError: simple_lru_cache__WEBPACK_IMPORTED_MODULE_0__ is not a constructor"},{"fix":"Ensure `var SimpleCache = require(\"simple-lru-cache\");` is at the top of your script file before any usage of `SimpleCache`.","cause":"The `SimpleCache` class was not properly imported or required before being used to instantiate a cache.","error":"ReferenceError: SimpleCache is not defined"},{"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.","cause":"Misunderstanding that `simple-lru-cache` only uses an LRU eviction policy and does not support time-to-live (TTL) for cache entries.","error":"(No explicit error, but unexpected behavior where items don't disappear after a time limit)"}],"ecosystem":"npm"}