Class: LruCache<K, V>
dg.LruCache
Least recently used cache. Inspired by https://github.com/Yomguithereal/mnemonist/blob/master/lru-cache.js
Type parameters
Name | Type |
---|---|
K | any |
V | any |
Constructors
constructor
• new LruCache<K
, V
>(capacity?
)
Type parameters
Name | Type |
---|---|
K | any |
V | any |
Parameters
Name | Type | Default value |
---|---|---|
capacity | number | 100 |
Defined in
Properties
K
• K: any
[]
Defined in
V
• V: any
[]
Defined in
backward
• Private
backward: Uint16Array
Defined in
capacity
• Private
capacity: number
Defined in
forward
• Private
forward: Uint16Array
Defined in
head
• Private
head: number
Defined in
items
• Private
items: Object
Defined in
onItemEvicted
• onItemEvicted: null
| Function
Defined in
size
• Private
size: number
Defined in
tail
• Private
tail: number
Defined in
Methods
get
▸ get(key
): undefined
| V
Gets the value attached to the given key, and makes it the most recently used item.
Parameters
Name | Type | Description |
---|---|---|
key | any | Key. |
Returns
undefined
| V
Defined in
getOrCreate
▸ getOrCreate(key
, createFromKey
): V
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
Name | Type | Description |
---|---|---|
key | K | Key. |
createFromKey | (key : K ) => V | Function to create a new item. |
Returns
V
Defined in
has
▸ has(key
): boolean
Checks whether the key exists in the cache.
Parameters
Name | Type | Description |
---|---|---|
key | any | Key. |
Returns
boolean
Defined in
set
▸ set(key
, value
): void
Sets the value for the given key in the cache.
Parameters
Name | Type | Description |
---|---|---|
key | any | Key. |
value | any | Value. |
Returns
void
Defined in
splayOnTop
▸ splayOnTop(pointer
): LruCache
<K
, V
>
Splays a value on top.
Parameters
Name | Type | Description |
---|---|---|
pointer | number | Pointer of the value to splay on top. |
Returns
LruCache
<K
, V
>