Constructor
new LruCache(limit, onEvictopt)
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
limit |
number | Maximum number of items allowed in the cache. |
||
onEvict |
function |
<optional> |
null | Optional callback triggered when an item is evicted. |
- Source:
Classes
Members
size
Returns the current number of items in the cache.
- Source:
Methods
clear()
Clears all items from the cache.
- Source:
delete(key) → {boolean}
Deletes an item from the cache.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string |
- Source:
Returns:
True if the item existed and was removed.
- Type
- boolean
get(key) → {*}
Retrieves an item from the cache and updates its recency.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string |
- Source:
Returns:
The cached value, or undefined if not found.
- Type
- *
has(key) → {boolean}
Checks if a key exists in the cache without updating its recency.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string |
- Source:
Returns:
- Type
- boolean
set(key, value)
Inserts or updates an item in the cache. Evicts the least recently used item if limit is exceeded.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | |
value |
* |
- Source: