Registry / storage / typescript-lru-cache

typescript-lru-cache

JSON →
library2.0.0jsnpmunverified

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.

npm install typescript-lru-cache
INSTALL
IMPORT
SIG · TYPESCRIPT-LRU-CAC
T
typescript-lru-cache
storagejavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LRUCache
✓ const { LRUCache } = require('typescript-lru-cache')
✗ const LRUCache = require('typescript-lru-cache')
CommonJS requires destructured import; default export is not provided.
LRUCache
✓ import { LRUCache } from 'typescript-lru-cache'
✗ import LRUCache from 'typescript-lru-cache'
ESM uses named import; there is no default export.
LRUCacheOptions
✓ import type { LRUCacheOptions } from 'typescript-lru-cache'
Type import for options interface; not a runtime value.
LRUCacheSetEntryOptions
✓ import type { LRUCacheSetEntryOptions } from 'typescript-lru-cache'
Type import for set entry options interface.

Creates an LRU cache with maxSize 3, adds four entries, demonstrating eviction of least recently used 'a' when 'd' is added.

import { LRUCache } from 'typescript-lru-cache'; const cache = new LRUCache<string, number>({ maxSize: 3 }); cache.set('a', 1); cache.set('b', 2); cache.set('c', 3); console.log(cache.get('a')); // 1 cache.set('d', 4); console.log(cache.get('a')); // undefined (evicted) console.log(cache.get('b')); // 2 console.log(cache.get('c')); // 3 console.log(cache.get('d')); // 4
Debug
Known issues
gotchaDefault maxSize is 25, not unlimited.
fix
Set maxSize explicitly if larger limit is needed, or expect eviction after 25 entries.
affects: >=1.0.0
gotchaClone option uses JSON.parse(JSON.stringify(value)) by default, which loses functions, undefined values, and circular references.
fix
Provide custom cloneFn if cloning non-serializable values.
affects: >=1.0.0
gotchaEntry expiration does not remove expired entries proactively; they are only evicted on subsequent access or set.
fix
Call cache.delete(key) explicitly or rely on get/set to trigger eviction.
affects: >=1.0.0
Errors
Common errors & fixes
LRUCache is not defined
Using default import instead of named import in ESM.
fix
Use `import { LRUCache } from 'typescript-lru-cache'`
TypeError: LRUCache is not a constructor
Wrong import style in CommonJS.
fix
Use `const { LRUCache } = require('typescript-lru-cache')`
Cannot destructure property 'LRUCache' of ... undefined
Not installing the package or incorrect package name.
fix
Run `npm install typescript-lru-cache` and verify package.json.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
30 hits · last 30 days
node
27
Resources
typescript-lru-cache — npm install typescript-lru-cache · libregistry