LruCache<K, V>
Defined in: src/utils.ts:511
Least recently used cache. Inspired by https://github.com/Yomguithereal/mnemonist/blob/master/lru-cache.js
Type Parameters
| Type Parameter | Default type |
|---|---|
K | any |
V | any |
Constructors
Constructor
new LruCache<
K,V>(capacity?):LruCache<K,V>
Defined in: src/utils.ts:523
Parameters
| Parameter | Type | Default value |
|---|---|---|
capacity | number | 100 |
Returns
LruCache<K, V>
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
K | public | any[] | src/utils.ts:511 |
onItemEvicted | public | Function | null | src/utils.ts:513 |
V | public | any[] | src/utils.ts:511 |
Methods
get()
get(
key):V|undefined
Defined in: src/utils.ts:624
Gets the value attached to the given key, and makes it the most recently used item.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | any | Key. |
Returns
V | undefined
getOrCreate()
getOrCreate(
key,createFromKey):V
Defined in: src/utils.ts:644
Returns the value with the specified key, if it already exists in the cache, or creates a new one by calling the provided function.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | K | Key. |
createFromKey | (key) => V | Function to create a new item. |
Returns
V
has()
has(
key):boolean
Defined in: src/utils.ts:569
Checks whether the key exists in the cache.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | any | Key. |
Returns
boolean
set()
set(
key,value):void
Defined in: src/utils.ts:579
Sets the value for the given key in the cache.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | any | Key. |
value | any | Value. |
Returns
void
splayOnTop()
splayOnTop(
pointer):LruCache<K,V>
Defined in: src/utils.ts:541
Splays a value on top.
Parameters
| Parameter | Type | Description |
|---|---|---|
pointer | number | Pointer of the value to splay on top. |
Returns
LruCache<K, V>