{"id":46717,"library":"typescript-lru-cache","title":"typescript-lru-cache","description":"A TypeScript-native LRU cache implementation with no runtime dependencies. Current stable version is 2.0.0. Uses a Map for internal storage, supporting any key type including reference types. Provides optional clone functionality, per-entry TTL, and eviction callbacks. Unlike other LRU caches (e.g., lru-cache), this package ships TypeScript source code and type definitions, and has a smaller API surface focusing on simplicity.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/rob893/typescript-lru-cache","tags":["javascript","cache","lru","typescript"],"install":[{"cmd":"npm install typescript-lru-cache","lang":"bash","label":"npm"},{"cmd":"yarn add typescript-lru-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add typescript-lru-cache","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS requires destructured import; default export is not provided.","wrong":"const LRUCache = require('typescript-lru-cache')","symbol":"LRUCache","correct":"const { LRUCache } = require('typescript-lru-cache')"},{"note":"ESM uses named import; there is no default export.","wrong":"import LRUCache from 'typescript-lru-cache'","symbol":"LRUCache","correct":"import { LRUCache } from 'typescript-lru-cache'"},{"note":"Type import for options interface; not a runtime value.","symbol":"LRUCacheOptions","correct":"import type { LRUCacheOptions } from 'typescript-lru-cache'"},{"note":"Type import for set entry options interface.","symbol":"LRUCacheSetEntryOptions","correct":"import type { LRUCacheSetEntryOptions } from 'typescript-lru-cache'"}],"quickstart":{"code":"import { LRUCache } from 'typescript-lru-cache';\n\nconst cache = new LRUCache<string, number>({ maxSize: 3 });\ncache.set('a', 1);\ncache.set('b', 2);\ncache.set('c', 3);\nconsole.log(cache.get('a')); // 1\ncache.set('d', 4);\nconsole.log(cache.get('a')); // undefined (evicted)\nconsole.log(cache.get('b')); // 2\nconsole.log(cache.get('c')); // 3\nconsole.log(cache.get('d')); // 4","lang":"typescript","description":"Creates an LRU cache with maxSize 3, adds four entries, demonstrating eviction of least recently used 'a' when 'd' is added."},"warnings":[{"fix":"Set maxSize explicitly if larger limit is needed, or expect eviction after 25 entries.","message":"Default maxSize is 25, not unlimited.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Provide custom cloneFn if cloning non-serializable values.","message":"Clone option uses JSON.parse(JSON.stringify(value)) by default, which loses functions, undefined values, and circular references.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Call cache.delete(key) explicitly or rely on get/set to trigger eviction.","message":"Entry expiration does not remove expired entries proactively; they are only evicted on subsequent access or set.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2.0.0':20 'api':66 'cach':4,10,48,52,72 'callback':44 'clone':36 'code':58 'current':16 'definit':61 'depend':15 'e.g':49 'entri':40 'evict':43 'focus':68 'function':37 'implement':11 'includ':31 'intern':25 'javascript':71 'key':29 'lru':3,9,47,51,73 'lru-cach':50 'map':23 'nativ':8 'option':35 'packag':54 'per':39 'per-entri':38 'provid':34 'refer':32 'runtim':14 'ship':55 'simplic':70 'smaller':65 'sourc':57 'stabl':17 'storag':26 'support':27 'surfac':67 'ttl':41 'type':30,33,60 'typescript':2,7,56,74 'typescript-lru-cach':1 'typescript-n':6 'unlik':45 'use':21 'version':18","created_at":"2026-06-07T13:01:17.523272+00:00","updated_at":"2026-06-07T13:01:17.523272+00:00","problems":[{"fix":"Use `import { LRUCache } from 'typescript-lru-cache'`","cause":"Using default import instead of named import in ESM.","error":"LRUCache is not defined"},{"fix":"Use `const { LRUCache } = require('typescript-lru-cache')`","cause":"Wrong import style in CommonJS.","error":"TypeError: LRUCache is not a constructor"},{"fix":"Run `npm install typescript-lru-cache` and verify package.json.","cause":"Not installing the package or incorrect package name.","error":"Cannot destructure property 'LRUCache' of ... undefined"}],"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/rob893/typescript-lru-cache#readme","github":"https://github.com/rob893/typescript-lru-cache","docs":null,"changelog":null,"pypi":null,"npm":"typescript-lru-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}}