Skip to main content

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 ParameterDefault type
Kany
Vany

Constructors

Constructor

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

Defined in: src/utils.ts:523

Parameters

ParameterTypeDefault value
capacitynumber100

Returns

LruCache<K, V>

Properties

PropertyModifierTypeDefined in
Kpublicany[]src/utils.ts:511
onItemEvictedpublicFunction | nullsrc/utils.ts:513
Vpublicany[]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

ParameterTypeDescription
keyanyKey.

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

ParameterTypeDescription
keyKKey.
createFromKey(key) => VFunction 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

ParameterTypeDescription
keyanyKey.

Returns

boolean


set()

set(key, value): void

Defined in: src/utils.ts:579

Sets the value for the given key in the cache.

Parameters

ParameterTypeDescription
keyanyKey.
valueanyValue.

Returns

void


splayOnTop()

splayOnTop(pointer): LruCache<K, V>

Defined in: src/utils.ts:541

Splays a value on top.

Parameters

ParameterTypeDescription
pointernumberPointer of the value to splay on top.

Returns

LruCache<K, V>