Skip to main content

LruCache<K, V>

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

Type parameters

Type parameterValue
Kany
Vany

Constructors

new LruCache()

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

Parameters

ParameterTypeDefault value
capacitynumber100

Returns

LruCache<K, V>

Source

src/utils.ts:495

Properties

PropertyModifierType
Kpublicany[]
Vpublicany[]
backwardprivateUint16Array
capacityprivatenumber
forwardprivateUint16Array
headprivatenumber
itemsprivateobject
onItemEvictedpublicnull | Function
sizeprivatenumber
tailprivatenumber

Methods

get()

get(key): undefined | V

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

Parameters

ParameterTypeDescription
keyanyKey.

Returns

undefined | V

Source

src/utils.ts:596


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

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

Returns

V

Source

src/utils.ts:616


has()

has(key): boolean

Checks whether the key exists in the cache.

Parameters

ParameterTypeDescription
keyanyKey.

Returns

boolean

Source

src/utils.ts:541


set()

set(key, value): void

Sets the value for the given key in the cache.

Parameters

ParameterTypeDescription
keyanyKey.
valueanyValue.

Returns

void

Source

src/utils.ts:551


splayOnTop()

splayOnTop(pointer): LruCache<K, V>

Splays a value on top.

Parameters

ParameterTypeDescription
pointernumberPointer of the value to splay on top.

Returns

LruCache<K, V>

Source

src/utils.ts:513