@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
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
| Parameter | Type | Description |
|---|---|---|
key | FeatureKey | Fully-qualified cache key. |
Returns
Promise<Series | undefined>
The stored series, or undefined if not present.
Implementation of
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
| Parameter | Type | Description |
|---|---|---|
prefix | Partial<FeatureKey> | Partial FeatureKey. Omitted fields match any value. |
Returns
Promise<void>
Implementation of
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
| Parameter | Type | Description |
|---|---|---|
key | FeatureKey | Fully-qualified cache key. |
series | Series | The computed series to store. Must not be mutated after passing to set. |
Returns
Promise<void>