fix: add WORLD_CACHE_SCHEMA_VERSION to cache key for automatic invalidation
Cache keys now include a schema version prefix so that world-schema changes automatically invalidate stale cached extraction results. Previously two incompatible schema versions would share the same cache key if URL/selectors/env matched, silently returning stale data. WORLD_CACHE_SCHEMA_VERSION exported publicly so consumers can increment it when making schema-incompatible changes to extraction. 658 tests pass.
This commit is contained in:
@@ -193,10 +193,17 @@ function djb2Hash(str: string): string {
|
|||||||
return hash.toString(16).padStart(8, '0')
|
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.
|
* Compute a stable cache key for a geometry extraction.
|
||||||
*
|
*
|
||||||
* The key incorporates:
|
* The key incorporates:
|
||||||
|
* - schema version (automatic invalidation on schema changes)
|
||||||
* - page URL
|
* - page URL
|
||||||
* - sorted selectors (so order doesn't matter)
|
* - sorted selectors (so order doesn't matter)
|
||||||
* - environment (viewport dimensions, color scheme, etc.)
|
* - environment (viewport dimensions, color scheme, etc.)
|
||||||
@@ -221,7 +228,7 @@ export function computeGeometryCacheKey(
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
const urlHash = djb2Hash(pageUrl)
|
const urlHash = djb2Hash(pageUrl)
|
||||||
return `${urlHash}-${selectorsHash}-${envHash}`
|
return `${WORLD_CACHE_SCHEMA_VERSION}-${urlHash}-${selectorsHash}-${envHash}`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ export {
|
|||||||
getDefaultCacheDir,
|
getDefaultCacheDir,
|
||||||
readCachedExtractionResult,
|
readCachedExtractionResult,
|
||||||
writeCachedExtractionResult,
|
writeCachedExtractionResult,
|
||||||
|
WORLD_CACHE_SCHEMA_VERSION,
|
||||||
} from './geometry-cache.js'
|
} from './geometry-cache.js'
|
||||||
|
|
||||||
// Public API type aliases for high-level evaluation results
|
// Public API type aliases for high-level evaluation results
|
||||||
|
|||||||
Reference in New Issue
Block a user