Constructor
new LruMap(maxSize)
Creates an LRU cache with specified maximum size.
Parameters:
Name | Type | Description |
---|---|---|
maxSize |
number | Maximum number of entries |
- Source:
Example
const cache = new LruMap(3);
cache.set('a', 1).set('b', 2).set('c', 3);
cache.set('d', 4); // Removes 'a', now contains b,c,d
Extends
- Map
Methods
set(key, value) → {this}
Sets a value, removing oldest entry if size limit reached.
Parameters:
Name | Type | Description |
---|---|---|
key |
* | The key to set |
value |
* | The value to store |
- Source:
Returns:
The LruMap instance for chaining
- Type
- this
Example
const cache = new LruMap(2);
cache.set('key1', 'value1')
.set('key2', 'value2')
.set('key3', 'value3'); // Removes key1