@pbroom/color-kit/planeCompile

runCachedPlaneQuery

Returns the cached result for a plane/query pair, or runs execute and caches what it returns.

functionimport { runCachedPlaneQuery } from '@pbroom/color-kit/plane';compile.ts:315
function 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

cachePlaneQueryCache
Cache to read from and write to.
planePlaneDefinition
Plane the query runs against; a Plane or any PlaneDefinition.
queryPlaneQuery
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

TypeScript
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