Skip to content
EliteChart

memoizeByKey

Documentation


Documentation / @elitechart/core / memoizeByKey

code
function memoizeByKey<A, R>(compute, keyFn): (...args) => R;

Defined in: util/memoize.ts:55

Wrap compute so repeated calls with the same keyFn(args) return the cached result. Single-slot — the most recent key wins.

Use when the compute depends on more than one input dimension; e.g. (bars, period) or (bars, { period, stdDev }).

Type Parameters

A

A extends readonly unknown[]

R

R

Parameters

compute

(...args) => R

keyFn

(...args) => string

Returns

(...args) => R

Example

code
const rsi14 = memoizeByKey(
    (bars: Bar[], period: number) => rsi(bars, { period }),
    (bars, period) => `${period}:${bars.length}:${bars[bars.length-1]?.time ?? 0}`,
  );