@livefolio/sdk / FeatureCache
Interface: FeatureCache
Defined in: interfaces/feature-cache.ts:87
Content-addressed cache for feature computation results.
Implementations MUST guarantee:
getreturns the exactSeriespreviously stored underkey, orundefinedif no entry exists. It MUST NOT return a stale or partially overlapping series.setstoresseriesunderkeyand makes it immediately available to subsequentgetcalls.invalidate(optional) removes all entries whose key fields match the suppliedprefix. Partial matches (specifying onlyfeature, for example) MUST invalidate every key that shares those fields, regardless of the remaining fields.- All methods are
async; implementations backed by in-process Maps may resolve synchronously viaPromise.resolve.
Reference implementation: MemoryFeatureCache — in-process Map, no eviction, suitable for single-run backtests.
Example
import { MemoryFeatureCache } from '@livefolio/sdk';
import type { FeatureKey, Series } from '@livefolio/sdk';
const cache = new MemoryFeatureCache();
const key: FeatureKey = {
feature: 'sma',
paramsHash: 'abc123',
scope: { kind: 'asset', asset: 'AAPL' },
range: { from: new Date('2024-01-01'), to: new Date('2025-01-01') },
freq: '1d',
};
const series: Series = [{ t: new Date('2024-01-02'), v: 150.5 }];
await cache.set(key, series);
const hit = await cache.get(key); // same referenceMethods
get()
get(
key):Promise<Series|undefined>
Defined in: interfaces/feature-cache.ts:95
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.
invalidate()?
optionalinvalidate(prefix):Promise<void>
Defined in: interfaces/feature-cache.ts:115
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>
set()
set(
key,series):Promise<void>
Defined in: interfaces/feature-cache.ts:104
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>