Skip to main content

Class: BoundedLruMap<K, V>

A Map that forgets its least-recently-used entry once it is full.

Caches keyed by voxel, chunk or block coordinate are the most common way a renderer grows without bound: the key space is effectively infinite over a session, so a plain Map retains one entry per coordinate the player ever touched. Reaching for this instead makes the bound explicit and gives the cache a capacity that lives in an option field.

Type parameters

Name
K
V

Constructors

constructor

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

Type parameters

Name
K
V

Parameters

NameTypeDescription
capacitynumberEntries retained before the least-recently-used one is evicted. A capacity below one disables the cache entirely.

Returns

BoundedLruMap<K, V>

Properties

capacity

Readonly capacity: number

Entries retained before the least-recently-used one is evicted. A capacity below one disables the cache entirely.

Accessors

size

get size(): number

Returns

number

Methods

clear

clear(): void

Returns

void


delete

delete(key): boolean

Parameters

NameType
keyK

Returns

boolean


get

get(key): V

Read an entry and mark it most-recently-used.

Parameters

NameType
keyK

Returns

V


has

has(key): boolean

Parameters

NameType
keyK

Returns

boolean


peek

peek(key): V

Read an entry without affecting eviction order.

Parameters

NameType
keyK

Returns

V


set

set(key, value): void

Parameters

NameType
keyK
valueV

Returns

void


values

values(): IterableIterator<V, any, any>

Entries from least- to most-recently-used.

Returns

IterableIterator<V, any, any>