Skip to main content

LruCache<K, V>

Defined in: js-api/src/utils.ts:525

Least recently used cache. Inspired by https://github.com/Yomguithereal/mnemonist/blob/master/lru-cache.js

Type Parameters​

Type ParameterDefault type
Kany
Vany

Constructors​

Constructor​

new LruCache<K, V>(capacity?): LruCache<K, V>

Defined in: js-api/src/utils.ts:538

Parameters​

ParameterTypeDefault value
capacitynumber100

Returns​

LruCache<K, V>

Properties​

PropertyModifierTypeDescriptionDefined in
Kpublicany[]-js-api/src/utils.ts:525
onItemEvictedpublic((value) => void) | nullCalled with the value that was just evicted.js-api/src/utils.ts:528
Vpublicany[]-js-api/src/utils.ts:525

Methods​

get()​

get(key): V | undefined

Defined in: js-api/src/utils.ts:634

Gets the value attached to the given key, and makes it the most recently used item.

Parameters​

ParameterTypeDescription
keyanyKey.

Returns​

V | undefined


getOrCreate()​

getOrCreate(key, createFromKey): V

Defined in: js-api/src/utils.ts:652

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​

ParameterTypeDescription
keyKKey.
createFromKey(key) => VFunction to create a new item.

Returns​

V


has()​

has(key): boolean

Defined in: js-api/src/utils.ts:581

Checks whether the key exists in the cache.

Parameters​

ParameterTypeDescription
keyanyKey.

Returns​

boolean


set()​

set(key, value): void

Defined in: js-api/src/utils.ts:590

Sets the value for the given key in the cache.

Parameters​

ParameterTypeDescription
keyanyKey.
valueanyValue.

Returns​

void


splayOnTop()​

splayOnTop(pointer): LruCache<K, V>

Defined in: js-api/src/utils.ts:554

Splays a value on top.

Parameters​

ParameterTypeDescription
pointernumberPointer of the value to splay on top.

Returns​

LruCache<K, V>