{"id":46386,"library":"simple.cache","title":"simple.cache","description":"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.","status":"active","version":"2.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/joaquimserafim/simple.cache","tags":["javascript","cache","lru","datastore","in-memory","typescript"],"install":[{"cmd":"npm install simple.cache","lang":"bash","label":"npm"},{"cmd":"yarn add simple.cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add simple.cache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import since version 2.0.0; CommonJS require still works but prefer ESM for compatibility with modern Node.js.","wrong":"const SimpleCache = require('simple.cache')","symbol":"SimpleCache","correct":"import SimpleCache from 'simple.cache'"},{"note":"This package has a default export, not named export. Using named import will result in undefined.","wrong":"import { SimpleCache } from 'simple.cache'","symbol":"SimpleCache","correct":"import SimpleCache from 'simple.cache'"},{"note":"SimpleCache is a factory function, not a constructor. Do not use 'new'.","wrong":"const cache = new SimpleCache(500)","symbol":"SimpleCache instance","correct":"const cache = SimpleCache(500)"}],"quickstart":{"code":"import SimpleCache from 'simple.cache';\n\nconst cache = SimpleCache(3); // max 3 entries\n\ncache.set('a', 1);\ncache.set('b', 2);\ncache.set('c', 3);\ncache.get('b'); // 2\ncache.set('d', 4); // evicts 'a' (LRU)\ncache.has('a'); // false\ncache.size(); // 3\ncache.keys(); // ['b', 'c', 'd']\ncache.remove('c');\ncache.dump(); // { b: 2, d: 4 }\ncache.clear();\nconsole.log('Done');","lang":"typescript","description":"Shows creating an LRU cache with max size, basic operations (set, get, has, remove, size, keys, dump, clear), and LRU eviction behavior."},"warnings":[{"fix":"Use import SimpleCache from 'simple.cache' instead of require('simple.cache').","message":"In 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'.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Call SimpleCache(max) directly without 'new'.","message":"SimpleCache is a factory function, not a class. Using 'new SimpleCache()' will throw a TypeError.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Do not expect a return from set(); it simply adds/updates the entry.","message":"The 'set' method does not return any value; attempting to use the return value (e.g., chaining) will give undefined.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always pass a positive integer to SimpleCache(max).","message":"The 'max' parameter must be a positive integer. Passing 0 or negative may result in unexpected behavior.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1000':28 '12':49 '2.0.4':15 'algorithm':55 'cach':11,21,65 'clear':37 'configur':24 'datastor':67 'default':27 'definit':46 'depend':63 'domin':57 'dump':40 'essenti':30 'extern':62 'get':33 'in-memori':8,68 'javascript':64 'key':38 'least':5 'lightweight':59 'lru':4,54,66 'maximum':25 'memori':10,70 'minim':3 'node.js':13,48 'oper':31 'packag':17 'provid':18 'recent':6 'remov':35 'set':32 'ship':42 'simple.cache':1 'size':26,36 'solut':22 'standard':53 'straightforward':20 'support':47 'tarr':58 'type':45 'typescript':44,71 'use':7,51 'version':14","created_at":"2026-06-07T12:59:40.178502+00:00","updated_at":"2026-06-07T12:59:40.178502+00:00","problems":[{"fix":"Use 'const cache = SimpleCache(100)' without 'new'.","cause":"Using 'new SimpleCache()' assuming it's a class.","error":"TypeError: SimpleCache is not a constructor"},{"fix":"Run 'npm install simple.cache' and use correct import: 'import SimpleCache from 'simple.cache''.","cause":"Package not installed or wrong import syntax.","error":"Cannot find module 'simple.cache'"},{"fix":"Ensure you have version 2.x or use CommonJS: 'const SimpleCache = require('simple.cache')'.","cause":"Using an older version that does not support ESM or incorrect import syntax.","error":"Uncaught SyntaxError: The requested module 'simple.cache' does not provide an export named 'default'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/joaquimserafim/simple.cache#readme","github":"https://github.com/joaquimserafim/simple.cache","docs":null,"changelog":null,"pypi":null,"npm":"simple.cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}