Documentation / @ripl/utilities / createLRUCache
Function: createLRUCache() ​
createLRUCache<
TKey,TValue>(limit):LRUCache<TKey,TValue>
Defined in: packages/utilities/src/cache.ts:99
Creates a bounded LRUCache, evicting the single least recently used entry when a write exceeds the limit.
Preferred over an unbounded memo wherever the key space is open-ended (paint strings, resolved geometry), since evicting one entry keeps every other caller's entry warm — wiping the whole cache at a threshold makes the steady state a permanent miss.
Type Parameters ​
| Type Parameter | Description |
|---|---|
TKey | Type of the cache key. |
TValue | Type of the cached value. |
Parameters ​
| Parameter | Type | Description |
|---|---|---|
limit | number | Maximum number of entries to retain. Values below 1 are clamped to 1. |
Returns ​
LRUCache<TKey, TValue>
The cache instance.
Example ​
ts
const cache = createLRUCache<string, number>(2);
cache.set('a', 1);
cache.set('b', 2);
cache.get('a');
cache.set('c', 3); // evicts 'b', the least recently used