fix(schema-compiler): include compilerId in template cache keys#10382
Open
michaelquery wants to merge 2 commits intocube-js:masterfrom
Open
fix(schema-compiler): include compilerId in template cache keys#10382michaelquery wants to merge 2 commits intocube-js:masterfrom
michaelquery wants to merge 2 commits intocube-js:masterfrom
Conversation
Template caches (YAML, Jinja, JS) used only MD5(file.content) as the cache key. When schemaVersion changed and recompilation was triggered, templates were served from cache because file content hadn't changed. This broke the documented behavior of schema_version, which states: "schema_version can be used to tell Cube that the data model should be recompiled in case it depends on dynamic definitions fetched from some external database or API." By including compilerId in the cache key, templates are now properly re-rendered when a new compilation is triggered via schemaVersion. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Resolves conflict with cube-js#10404 (Remove JSON.stringify in cache key hashing) by combining both changes: use file.content directly AND include compilerId.
dabdab8 to
4eb2a85
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10383
Summary
Template caches (
compiledYamlCache,compiledJinjaCache,compiledScriptCache) used onlyMD5(file.content)as the cache key. WhenschemaVersionchanged and recompilation was triggered, templates were served from cache because file content hadn't changed.This broke the documented behavior of
schema_version, which states:The Fix
Include
compilerId(already available as an instance property) in the cache key hash:When
schemaVersionchanges → recompilation triggered → newcompilerId→ cache miss → templates re-rendered.Minimal Reproduction (before fix)
Expected:
compiled_atshows new timestamp on every request (sinceschema_versionchanges)Actual (before fix): Timestamp never changes—template served from cache despite "Recompiling schema" log
Current Workaround (and why it's problematic)
The only workaround is to include schema-affecting config in
app_id:This causes memory bloat and resource duplication because each
app_idcreates a newCompilerApiwith its own resources, including data model compile cache, SQL compile cache, query queues, in-memory result caching, etc. The multitenancy docs explicitly warn about this overhead:Side Effects
schema_versionchangesIn dev mode, when any file changes, a new
compilerIdis generated. This means all templates are re-rendered, not just the changed file. Previously, unchanged templates would hit the cache.Why this is acceptable:
devServerare unaffectedIf a more surgical fix is preferred,
compilerIdcould be conditionally included only for templates containing Jinja syntax (indicating dynamic content).Test Plan
compilerIdvaluesyarn test --testPathPattern="template-cache-invalidation"