{"id":45397,"library":"memory-cache","title":"memory-cache","description":"A simple in-memory cache for Node.js with support for TTL and expiration callbacks. Version 0.2.0 is stable with no recent releases; it uses setTimeout for expiration. Unlike more feature-rich solutions (e.g., node-cache, lru-cache), it offers a minimal API: put, get, del, clear, size, and import/export. Its constructor allows multiple isolated cache instances. Note that all operations are synchronous, and hits/misses are only tracked in debug mode.","status":"maintenance","version":"0.2.0","language":"javascript","source_language":"en","source_url":"git://github.com/ptarjan/node-cache","tags":["javascript","cache","ram","simple","storage"],"install":[{"cmd":"npm install memory-cache","lang":"bash","label":"npm"},{"cmd":"yarn add memory-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add memory-cache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS-only; no default ES module export. Use require().","wrong":"import cache from 'memory-cache';","symbol":"default instance","correct":"const cache = require('memory-cache');"},{"note":"Both patterns work, but destructuring is idiomatic.","wrong":"const Cache = require('memory-cache').Cache;","symbol":"Cache class","correct":"const { Cache } = require('memory-cache');"},{"note":"Second argument must be an options object, not a boolean.","wrong":"cache.importJson(json, true);","symbol":"importJson options","correct":"cache.importJson(json, { skipDuplicates: true });"}],"quickstart":{"code":"const cache = require('memory-cache');\n\n// store a value indefinitely\ncache.put('foo', 'bar');\nconsole.log(cache.get('foo')); // 'bar'\n\n// store with TTL (100ms) and expiration callback\ncache.put('houdini', 'disappear', 100, function(key, value) {\n  console.log(key + ' did ' + value);\n});\nconsole.log(cache.get('houdini')); // 'disappear'\n\nsetTimeout(() => {\n  console.log(cache.get('houdini')); // null (expired)\n}, 200);\n\n// create a separate cache instance\nconst myCache = new cache.Cache();\nmyCache.put('key', 'value');\nconsole.log(myCache.get('key')); // 'value'","lang":"javascript","description":"Demonstrates basic put/get, TTL with callback, cache expiration, and creating a separate Cache instance."},"warnings":[{"fix":"Enable debug mode: cache.debug(true); before checking hits/misses.","message":"Hits and misses are only tracked when debug mode is enabled via cache.debug(true).","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Do not rely on exact millisecond expiration for timing-critical use cases.","message":"TTL uses setTimeout internally; accuracy may be affected by Node.js event loop delays.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Pass skipDuplicates: true to preserve existing keys.","message":"importJson with skipDuplicates: false (default) overwrites duplicate keys silently.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider alternatives like node-cache or lru-cache for active development.","message":"No new releases since 2017; package is in maintenance mode.","severity":"deprecated","affected_versions":">0.2.0"}],"env_vars":null,"search_vec":"'0.2.0':20 'allow':59 'api':49 'cach':3,9,41,44,62,79 'callback':18 'clear':53 'constructor':58 'debug':76 'del':52 'e.g':38 'expir':17,31 'featur':35 'feature-rich':34 'get':51 'hits/misses':71 'import/export':56 'in-memori':6 'instanc':63 'isol':61 'javascript':78 'lru':43 'lru-cach':42 'memori':2,8 'memory-cach':1 'minim':48 'mode':77 'multipl':60 'node':40 'node-cach':39 'node.js':11 'note':64 'offer':46 'oper':67 'put':50 'ram':80 'recent':25 'releas':26 'rich':36 'settimeout':29 'simpl':5,81 'size':54 'solut':37 'stabl':22 'storag':82 'support':13 'synchron':69 'track':74 'ttl':15 'unlik':32 'use':28 'version':19","created_at":"2026-06-07T12:54:48.748191+00:00","updated_at":"2026-06-07T12:54:48.748191+00:00","problems":[{"fix":"Use const cache = require('memory-cache'); to get the default instance.","cause":"Requiring the module incorrectly, e.g. const cache = require('memory-cache').Cache; returns the class, not the default instance.","error":"TypeError: cache.get is not a function"},{"fix":"Switch to CommonJS or use a dynamic import: const cache = await import('memory-cache'); (note: package is not ESM).","cause":"Using import statement or running in ES module mode.","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Ensure the third argument is a number (time in ms).","cause":"TTL value must be a number in milliseconds; if omitted or non-number, callback is ignored.","error":"cache.put('key', 'value', 100, function(key, value) { ... }) but callback never called"}],"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/ptarjan/node-cache#readme","github":"git://github.com/ptarjan/node-cache","docs":null,"changelog":null,"pypi":null,"npm":"memory-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}}