detritus

BaseCollection<K, V>class

A Map-like collection with array-style helpers, an optional size limit (least recently used are evicted first) and optional expiry.

On this page
import { BaseCollection } from 'detritus-utils';
BaseCollectionMixin<K, V>BaseCollection
<K, V>
9 properties20 methods14 inheritedsrc/basecollection.ts:146

Constructor

Properties

_intervalTime
number
_lastUsed?
Map<K, number>
optional
_order?
Map<K, true>
optional
cache
Map<K, V>
readonly
expire?
number
readonlyoptional
interval?
optional
Default undefined
intervalTime
number
readonly
Default 5000
limit
number
Default Infinity

Accessors

[toStringTag]
string
get
isSweeping
boolean
get

If the expiry interval is running, only while items expire and the collection isn't empty

lastUsed
Map<K, number>
get
length
number
get
shouldStartInterval
boolean
get
size
number
get

Methods

evict()

src/basecollection.ts:453
evict(room?: number): void

Evicts the least recently used items until there's room free under the limit

room?
number
Default 0

getOrder()

src/basecollection.ts:474
getOrder(): Map<K, true>

The recency order (least recently used first), synced with the cache untracked keys (added while limit was Infinity) count as the least recently used