Skip to content

@livefolio/sdk / MemoryFeatureCache

Class: MemoryFeatureCache

Defined in: reference/memory-feature-cache.ts:59

In-process, Map-backed implementation of FeatureCache. Caches computed indicator series in memory for the lifetime of the instance. There is no eviction policy — the cache grows until the instance is garbage-collected.

When to use: the right choice for single-run backtests or unit tests where the full dataset fits in process memory and cross-run persistence is not required. For long-running hosted services or multi-process setups, substitute a persistent implementation (e.g. Redis-backed) that satisfies the FeatureCache interface.

Cache keys are content-addressed strings composed of (feature kind, params hash, asset scope, date range, frequency) — see the internal canonicalKey function. The invalidate method performs prefix-based deletion using the same key segments.

Example

ts
import { MemoryFeatureCache } from '@livefolio/sdk';
import { FeatureRuntime } from '@livefolio/sdk/features';

const cache   = new MemoryFeatureCache();
const runtime = new FeatureRuntime({ feed: myDataFeed, cache });

Implements

Constructors

Constructor

new MemoryFeatureCache(): MemoryFeatureCache

Returns

MemoryFeatureCache

Methods

get()

get(key): Promise<Series | undefined>

Defined in: reference/memory-feature-cache.ts:62

Retrieves the cached Series for key, or undefined on a cache miss.

Parameters

ParameterTypeDescription
keyFeatureKeyFully-qualified cache key.

Returns

Promise<Series | undefined>

The stored series, or undefined if not present.

Implementation of

FeatureCache.get


invalidate()

invalidate(prefix): Promise<void>

Defined in: reference/memory-feature-cache.ts:70

Removes all cache entries whose keys match the supplied prefix. Optional — implementations that do not support invalidation may omit this.

Matching is field-by-field: only the fields present in prefix are compared; all others are treated as wildcards.

Parameters

ParameterTypeDescription
prefixPartial<FeatureKey>Partial FeatureKey. Omitted fields match any value.

Returns

Promise<void>

Implementation of

FeatureCache.invalidate


set()

set(key, series): Promise<void>

Defined in: reference/memory-feature-cache.ts:66

Stores series under key. Overwrites any existing entry at that key.

Parameters

ParameterTypeDescription
keyFeatureKeyFully-qualified cache key.
seriesSeriesThe computed series to store. Must not be mutated after passing to set.

Returns

Promise<void>

Implementation of

FeatureCache.set

Released under the MIT License.