@pbroom/color-kit/planeCompile
runCachedPlaneQuery
Returns the cached result for a plane/query pair, or runs execute and caches what it returns.
import { runCachedPlaneQuery } from '@pbroom/color-kit/plane';compile.ts:315function runCachedPlaneQuery(
cache: PlaneQueryCache,
plane: PlaneDefinition,
query: PlaneQuery,
execute: () => PlaneQueryResult,
): PlaneQueryResult;execute is called only on a cache miss; it is not checked against query, so it must compute the result for that same plane and query.
Parameters
- cache
PlaneQueryCache - Cache to read from and write to.
- plane
PlaneDefinition - Plane the query runs against; a
Planeor anyPlaneDefinition. - query
PlaneQuery - Query payload, used for the cache key.
- execute
() => PlaneQueryResult - Computes the result on a miss (for example
() => runPlaneQuery(plane, query)).
Returns
PlaneQueryResultThe cached or freshly computed result (same reference on a hit).
Example
import {
definePlane,
getPlaneGamutBoundary,
PlaneQueryCache,
runCachedPlaneQuery,
} from '@pbroom/color-kit/plane';
const cache = new PlaneQueryCache({ maxEntries: 32 });
const plane = definePlane({ fixed: { h: 264 } });
const query = { kind: 'gamutBoundary' } as const;
const first = runCachedPlaneQuery(cache, plane, query, () =>
getPlaneGamutBoundary(plane),
);
const second = runCachedPlaneQuery(cache, plane, query, () =>
getPlaneGamutBoundary(plane),
);
first === second; // → true (execute ran once)Also exported from
@pbroom/color-kitthe same declaration, re-exported