Skip to main content

Class: WeakMapStorage<V>

@ima/core.WeakMapStorage

A specialization of the link MapStorage storage mimicking the native WeakMap using its internal garbage collector used once the size of the storage reaches the configured threshold.

Type parameters

NameType
Vobject

Hierarchy

Constructors

constructor

new WeakMapStorage<V>(config)

Initializes the storage.

Type parameters

NameType
Vobject

Parameters

NameTypeDescription
configObjectWeak map storage configuration. The fields have the following meaning: - entryTtl The time-to-live of a storage entry in milliseconds.
config.entryTtlnumber-

Overrides

Storage.constructor

Defined in

packages/core/src/storage/WeakMapStorage.ts:26

Properties

_entryTtl

Private _entryTtl: number

The time-to-live of a storage entry in milliseconds.

Defined in

packages/core/src/storage/WeakMapStorage.ts:12


_storage

Private _storage: Map<string, WeakRef<V>>

The internal storage of entries.

Defined in

packages/core/src/storage/WeakMapStorage.ts:17

Methods

_discardExpiredEntries

_discardExpiredEntries(): void

Deletes all expired entries from this storage.

Returns

void

Defined in

packages/core/src/storage/WeakMapStorage.ts:101


clear

clear(): WeakMapStorage<V>

Clears the storage of all entries.

Returns

WeakMapStorage<V>

This storage.

Overrides

Storage.clear

Defined in

packages/core/src/storage/WeakMapStorage.ts:74


delete

delete(key): WeakMapStorage<V>

Deletes the entry identified by the specified key from this storage.

Parameters

NameTypeDescription
keystringThe key identifying the storage entry.

Returns

WeakMapStorage<V>

This storage.

Overrides

Storage.delete

Defined in

packages/core/src/storage/WeakMapStorage.ts:67


get

get(key): undefined | V

Retrieves the value of the entry identified by the specified . The method returns undefined if the entry does not exists.

Entries set to the undefined value can be tested for existence using the link has method.

Parameters

NameTypeDescription
keystringThe key identifying the storage entry.

Returns

undefined | V

The value of the storage entry.

Overrides

Storage.get

Defined in

packages/core/src/storage/WeakMapStorage.ts:44


has

has(key): boolean

Returns true if the entry identified by the specified key exists in this storage.

Parameters

NameTypeDescription
keystringThe key identifying the storage entry.

Returns

boolean

true if the storage entry exists.

Overrides

Storage.has

Defined in

packages/core/src/storage/WeakMapStorage.ts:35


init

init(): WeakMapStorage<V>

This method is used to finalize the initialization of the storage after the dependencies provided through the constructor have been prepared for use.

This method must be invoked only once and it must be the first method invoked on this instance.

Returns

WeakMapStorage<V>

This storage.

Inherited from

Storage.init

Defined in

packages/core/src/storage/Storage.ts:17


keys

keys(): Iterable<string>

Returns an iterator for traversing the keys in this storage. The order in which the keys are traversed is undefined.

Returns

Iterable<string>

An iterator for traversing the keys in this storage. The iterator also implements the iterable protocol, returning itself as its own iterator, allowing it to be used in a for..of loop.

Overrides

Storage.keys

Defined in

packages/core/src/storage/WeakMapStorage.ts:83


set

set(key, value): WeakMapStorage<V>

Sets the storage entry identified by the specified key to the provided value. The method creates the entry if it does not exist already.

Parameters

NameTypeDescription
keystringThe key identifying the storage entry.
valueVThe storage entry value.

Returns

WeakMapStorage<V>

This storage.

Overrides

Storage.set

Defined in

packages/core/src/storage/WeakMapStorage.ts:57


size

size(): number

Returns the number of entries in this storage.

Returns

number

The number of entries in this storage.

Overrides

Storage.size

Defined in

packages/core/src/storage/WeakMapStorage.ts:92