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.
We currently use this HTTP caching strategy on trunk:
remote-data-blocks/inc/Config/Query/HttpQuery.php
Lines 43 to 48 in 4f6e62a
The comment is incorrect. We inherit the same strategy in
GraphqlQuery
, and this has some issues. GraphQL queries are typically implemented asPOST
requests, which means that we're skipping the cache each time we make a GraphQL query. For large pages of items or a lot of properties, this results in a huge number of cache misses and slow page loads for our GraphQL data sources like Shopify.This PR adjusts GraphQL queries to use the default caching strategy, ignoring the fact that it's a
POST
request. GraphQL mutations are still uncached.Testing
On the
trunk
branch, set up a Shopify connection.Create a new post and add a product with the default template.
Publish the page and view the page on the frontend as a logged-in user (e.g. as
admin
on a localwp-env
instance).View the Query Monitor logs by clicking on the query monitor bar (top arrow) and clicking the "Logs" tab on the lower left:
Note the several logs related to cache misses. Refresh the page and confirm that caching is not working.
Switch to this branch
fix/graphql-caching
.Refresh the page. You should see one cache miss follow by several cache hits:
Refresh again. All requests should hit the cache now, and the page should load very quickly.
Wait 60 seconds and refresh. You should see a fresh uncached request followed by cached result, the same as step 7.