Prevent stale GraphQL responses in the static cache - #199
Conversation
There was a problem hiding this comment.
Pull request overview
Disables Craft GraphQL result caching when the StaticCache component starts collecting element cache information, intended to ensure static cache metadata is collected from real element queries rather than cached GraphQL responses.
Changes:
- Turn off
enableGraphqlCachingwhen static cache-info collection begins.
Suppressed comments (2)
src/StaticCache.php:146
- This disables GraphQL caching by mutating the global General config, but the setting is never restored. Since cache-info collection is stopped later (and may not be stopped at all if the response becomes non-cacheable before
EVENT_AFTER_PREPARE), this can leave GraphQL caching disabled and element cache-info collection running longer than intended within the request.
}
}
});
src/StaticCache.php:144
- New behavior (toggling
enableGraphqlCachingduring cache-info collection) is not covered by unit tests. There are existing unit tests forStaticCache(e.g. cacheability and header behaviors), so this should be straightforward to cover to prevent regressions in future Craft updates.
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Suppressed comments (1)
tests/unit/StaticCacheTest.php:629
- This helper invokes a private method via ReflectionMethod without calling
setAccessible(true), so the invocation will fail. Align this with the other reflection helpers in this test file by making the method accessible first.
$method = new ReflectionMethod($staticCache, 'handleBeforeExecuteGqlQuery');
$method->invoke($staticCache, new \yii\base\Event());
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
tests/unit/StaticCacheTest.php:140
- The test sets a private
$collectingCacheInfoproperty viaReflectionPropertywithout callingsetAccessible(true). Other helpers in this test file callsetAccessible(true)for private members, and without it this will throw when the property is non-public.
$collectingCacheInfo = new ReflectionProperty($staticCache, 'collectingCacheInfo');
$collectingCacheInfo->setValue($staticCache, true);
Summary
GraphQL responses could be stored in the static cache without the element dependencies needed to invalidate them. Changes to queried elements would not purge those responses, leaving stale content cached until it expired.
Ensure statically cached GraphQL responses are invalidated when their queried elements change.