{"id":46635,"library":"tlru","title":"tlru","description":"Time-aware least recently used (TLRU) cache for Node.js, version 1.1.1. Extends native Map with proactive eviction using a single timer via fun-dispatcher, avoiding linked lists for memory efficiency. Key differentiators: supports per-item TTL, optional LRU mode with maxStoreSize, can revive items on get. Maintained by tinovyatkin. Requires Node >=18, includes TypeScript types.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/tinovyatkin/tlru","tags":["javascript","LRU","cache","expires","lru-cache","receptacle","setTimeout","time-aware","tlru","typescript"],"install":[{"cmd":"npm install tlru","lang":"bash","label":"npm"},{"cmd":"yarn add tlru","lang":"bash","label":"yarn"},{"cmd":"pnpm add tlru","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for timer management","package":"fun-dispatcher","optional":false}],"imports":[{"note":"Named export only. Default import will not work.","wrong":"import TLRU from 'tlru'","symbol":"TLRU","correct":"import { TLRU } from 'tlru'"},{"note":"CommonJS requires destructuring.","wrong":"const TLRU = require('tlru')","symbol":"TLRU","correct":"const { TLRU } = require('tlru')"},{"note":"TypeScript type import allowed.","wrong":"","symbol":"TLRU","correct":"import type { TLRU } from 'tlru'"}],"quickstart":{"code":"import { TLRU } from 'tlru';\n\nconst cache = new TLRU({ maxStoreSize: 5, maxAgeMs: 1000 });\ncache.set('key1', { data: 'value1' }, 500); // TTL 500ms\ncache.set('key2', 'value2'); // defaults to 1000ms\nconsole.log(cache.get('key1')); // { data: 'value1' }\ncache.has('key2'); // true\nsetTimeout(() => {\n  console.log(cache.has('key1')); // false (expired)\n}, 600);","lang":"typescript","description":"Creates a TLRU cache with max 5 items, each with a default 1 second TTL. Demonstrates set with custom TTL, get, has, and automatic expiration."},"warnings":[{"fix":"Upgrade Node.js to version 18 or later.","message":"Node.js version requirement is >=18. Older versions are not supported and will cause errors.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use maxAgeMs instead of maxAge.","message":"The 'maxAge' option was deprecated in favor of 'maxAgeMs' in version 1.0.0.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Wait for setImmediate or setTimeout(0) before relying on evictions for size or keys.","message":"Cache eviction is lazy and happens on next timer tick (setImmediate). Checking immediately after set may show stale data.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use has() to check existence, not truthiness of get() result.","message":"Extending Map: get() returns undefined for missing keys, but also for keys with undefined values. No way to distinguish.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"When using defaultLRU: true, you must provide maxStoreSize.","message":"TLRU constructor throws if maxStoreSize is not provided when defaultLRU is true.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.1.1':13 '18':56 'avoid':28 'awar':4,71 'cach':9,62,66 'differenti':35 'dispatch':27 'effici':33 'evict':19 'expir':63 'extend':14 'fun':26 'fun-dispatch':25 'get':50 'includ':57 'item':39,48 'javascript':60 'key':34 'least':5 'link':29 'list':30 'lru':42,61,65 'lru-cach':64 'maintain':51 'map':16 'maxstores':45 'memori':32 'mode':43 'nativ':15 'node':55 'node.js':11 'option':41 'per':38 'per-item':37 'proactiv':18 'recent':6 'receptacl':67 'requir':54 'reviv':47 'settimeout':68 'singl':22 'support':36 'time':3,70 'time-awar':2,69 'timer':23 'tinovyatkin':53 'tlru':1,8,72 'ttl':40 'type':59 'typescript':58,73 'use':7,20 'version':12 'via':24","created_at":"2026-06-07T13:00:52.894282+00:00","updated_at":"2026-06-07T13:00:52.894282+00:00","problems":[{"fix":"Use import { TLRU } from 'tlru' instead of import TLRU from 'tlru'.","cause":"Incorrect import: default import instead of named import.","error":"TLRU is not a constructor"},{"fix":"Ensure using require('tlru') correctly, or switch to import.","cause":"Using CommonJS require with ESM-only version of the package? (tlru supports CJS, but only via require('tlru').)","error":"ERR_REQUIRE_ESM: require() of ES Module not supported"},{"fix":"Use const lru = new TLRU({...});","cause":"TLRU is not instantiated; forgetting new keyword.","error":"TypeError: lru.set is not a function"}],"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/tinovyatkin/tlru#readme","github":"https://github.com/tinovyatkin/tlru","docs":null,"changelog":null,"pypi":null,"npm":"tlru","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}}