Skip to main content

Class: CachedValue<T>

Defined in: src/sdk/sub/CachedValue.ts:10

A cached accessible value backed by a source Accessible. Every time the cached value's state is retrieved, it is checked to determine whether it is valid. If it is valid, then the cached state is returned unchanged. If it is not valid, then the cached state is updated with the state of the source Accessible before it is returned. Once updated with the state of the source Accessible, the cached state remains valid until it is manually invalidated.

Type Parameters

Type ParameterDescription
TThe type of the value.

Implements

Methods

get()

get(): T

Defined in: src/sdk/sub/CachedValue.ts:36

Gets the cached state of this value. If the cached state is valid, then the cached state will be returned as-is. Otherwise, the cached state will be updated with the state of this value's source Accessible before it is returned, and the cached state will be marked as valid.

Returns

T

This value's cached state.

Implementation of

Accessible.get


invalidate()

invalidate(): void

Defined in: src/sdk/sub/CachedValue.ts:50

Invalidates the cached state of this value. The next time get() is called, the cached state will be updated with with the state of this value's source Accessible.

Returns

void


create()

static create<T>(source): CachedValue<T>

Defined in: src/sdk/sub/CachedValue.ts:26

Creates a new instance of CachedValue. The new instance is initialized with an invalid cached state.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
sourceAccessible<T>The accessible that is the source of the new cached value.

Returns

CachedValue<T>

A new instance of CachedValue backed by the specified Accessible.