Skip to content

Prevent stale GraphQL responses in the static cache - #199

Closed
timkelty wants to merge 6 commits into
3.xfrom
t3code/investigate-gql-static-caching
Closed

Prevent stale GraphQL responses in the static cache#199
timkelty wants to merge 6 commits into
3.xfrom
t3code/investigate-gql-static-caching

Conversation

@timkelty

@timkelty timkelty commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

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.

Copilot AI lite review requested due to automatic review settings August 28, 2026 14:20
@timkelty timkelty changed the title Disable GraphQL caching during static cache collection Prevent stale GraphQL responses in the static cache Aug 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 enableGraphqlCaching when 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 enableGraphqlCaching during cache-info collection) is not covered by unit tests. There are existing unit tests for StaticCache (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.

Copilot AI review requested due to automatic review settings August 28, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread src/StaticCache.php
Comment thread src/StaticCache.php
@timkelty
timkelty marked this pull request as draft August 28, 2026 14:36
Copilot AI review requested due to automatic review settings August 28, 2026 14:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
    }

Comment thread tests/unit/StaticCacheTest.php
Comment thread src/StaticCache.php
Copilot AI review requested due to automatic review settings August 28, 2026 14:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 $collectingCacheInfo property via ReflectionProperty without calling setAccessible(true). Other helpers in this test file call setAccessible(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);

Comment thread tests/unit/StaticCacheTest.php
Copilot AI review requested due to automatic review settings August 28, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 28, 2026 16:29
@timkelty timkelty closed this Aug 28, 2026
@timkelty
timkelty deleted the t3code/investigate-gql-static-caching branch August 28, 2026 16:29
Copilot stopped reviewing on behalf of timkelty due to an error August 28, 2026 16:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread src/StaticCache.php
Comment thread src/StaticCache.php
Comment thread tests/unit/StaticCacheTest.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants