@pbroom/color-kit/planeCompile
PlaneQueryCache
LRU cache of plane query results, keyed by createPlaneQueryKey.
import { PlaneQueryCache } from '@pbroom/color-kit/plane';compile.ts:217class 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
- options?
PlaneQueryCacheOptionsdefault{}
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
truewhen 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
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); // → trueAlso exported from
@pbroom/color-kitthe same declaration, re-exported