@pbroom/color-kit/planeCompile

PlaneQueryCache

LRU cache of plane query results, keyed by createPlaneQueryKey.

classimport { PlaneQueryCache } from '@pbroom/color-kit/plane';compile.ts:217
class PlaneQueryCache {
  constructor(    options?: PlaneQueryCacheOptions,  );
  get(
    plane: PlaneDefinition,
    query: PlaneQuery,
  ): PlaneQueryResult | undefined;
  set(
    plane: PlaneDefinition,
    query: PlaneQuery,
    result: PlaneQueryResult,
  ): void;
  has(    plane: PlaneDefinition, ,    query: PlaneQuery,  ): boolean;
  clear(): void;
  invalidateByPrefix(    prefix: string,  ): number;
}

Reads (get, has) refresh an entry's recency and writes evict the least-recently-used entries once PlaneQueryCacheOptions.maxEntries is exceeded. Results are stored and returned by reference; treat them as read-only. Pair it with runCachedPlaneQuery.

Parameters

Members

get(plane: PlaneDefinition, query: PlaneQuery) => PlaneQueryResult | undefinedmethod
Gets a cached query result for the given plane/query pair.
set(plane: PlaneDefinition, query: PlaneQuery, result: PlaneQueryResult) => voidmethod
Stores a query result for the given plane/query pair.
has(plane: PlaneDefinition, query: PlaneQuery) => booleanmethod
Returns true when a cached value exists for the plane/query pair.
clear() => voidmethod
Clears all cached query entries.
invalidateByPrefix(prefix: string) => numbermethod
Deletes all entries whose key starts with prefix.

Example

TypeScript
import { definePlane, PlaneQueryCache, runPlaneQuery } from '@pbroom/color-kit/plane';

const cache = new PlaneQueryCache({ maxEntries: 1 });
const plane = definePlane({ fixed: { h: 264 } });
const a = { kind: 'gamutBoundary' } as const;
const b = { kind: 'chromaBand' } as const;
cache.set(plane, a, runPlaneQuery(plane, a));
cache.set(plane, b, runPlaneQuery(plane, b)); // evicts `a`
cache.has(plane, a); // → false
cache.has(plane, b); // → true

Also exported from