diff --git a/packages/imhotep-core/src/geometry-cache.ts b/packages/imhotep-core/src/geometry-cache.ts index 74bc1e9..b32f3e0 100644 --- a/packages/imhotep-core/src/geometry-cache.ts +++ b/packages/imhotep-core/src/geometry-cache.ts @@ -193,10 +193,17 @@ function djb2Hash(str: string): string { return hash.toString(16).padStart(8, '0') } +/** + * Schema version for cache invalidation. Increment when the world schema + * changes in a way that makes previously cached extraction results incompatible. + */ +export const WORLD_CACHE_SCHEMA_VERSION = 2 + /** * Compute a stable cache key for a geometry extraction. * * The key incorporates: + * - schema version (automatic invalidation on schema changes) * - page URL * - sorted selectors (so order doesn't matter) * - environment (viewport dimensions, color scheme, etc.) @@ -221,7 +228,7 @@ export function computeGeometryCacheKey( }), ) const urlHash = djb2Hash(pageUrl) - return `${urlHash}-${selectorsHash}-${envHash}` + return `${WORLD_CACHE_SCHEMA_VERSION}-${urlHash}-${selectorsHash}-${envHash}` } // --------------------------------------------------------------------------- diff --git a/packages/imhotep-core/src/index.ts b/packages/imhotep-core/src/index.ts index 145e099..b3a447d 100644 --- a/packages/imhotep-core/src/index.ts +++ b/packages/imhotep-core/src/index.ts @@ -60,6 +60,7 @@ export { getDefaultCacheDir, readCachedExtractionResult, writeCachedExtractionResult, + WORLD_CACHE_SCHEMA_VERSION, } from './geometry-cache.js' // Public API type aliases for high-level evaluation results