Cache queries#2017
Conversation
| Query caching is enabled in non-local environments by default. You can define cache store and cache duration, | ||
| see `config/lighthouse.php`. | ||
|
|
||
| The GraphQL schema doesn't affect query parsing, so you have to flush query cache only on the package update. |
There was a problem hiding this comment.
| The GraphQL schema doesn't affect query parsing, so you have to flush query cache only on the package update. | |
| Make sure to flush the query cache when you deploy an upgraded version of the dependency `webonyx/graphql-php`: | |
| some-one-liner that clears the cache? |
There was a problem hiding this comment.
I can add another command like lighthouse:query:cache:clear but it only clears the cache store. So I guess it's easier to just use the laravel default command.
There was a problem hiding this comment.
That Laravel command clears all caches?
There was a problem hiding this comment.
it fully clears the default store. If the user specified non-default store for query cache they should add an argument to the command
php artisan cache:clear --store=query_cache_store
|
I need to think about the deprecation of Perhaps we should extract a method |
Co-authored-by: Benedikt Franke <benedikt@franke.tech>
This method might also throw a |
|
I could imagine the memoized |
|
I extracted the |
spawnia
left a comment
There was a problem hiding this comment.
Like the extracted method, just a few more nits regarding the docs.
Considering Automated persisted queries, would you foresee further changes to the proposed API?
Co-authored-by: Benedikt Franke <benedikt@franke.tech>
I don't thinks this API will have any changes. We will have to add another method like |
|
The API of the I can look into this myself, but am also quite happy if you push it further. |
|
I added the APQ support. As for config schema: I guess the better cache format will be like this: 'cache' => [
'schema' => [
'version' => env('LIGHTHOUSE_CACHE_VERSION', 1),
// other parameters that are currently in the cache.*
],
'query' => [
// parameters from query_cache
],
'validate' => [
// future parameters for https://github.com/nuwave/lighthouse/issues/2018
],
]But it will break backward compatibility. So I guess it's easier to leave as is and refactor it in the next major version. |
|
@k0ka invited you as a collaborator. If you would like to join our Slack, I can add you to our collaborator chat as well. |
Changes
Query caching has been added: the result of
GraphQL\Language\Parser::parse()will be serialized and stored in the Laravel cache. It can be disabled in the config.I tested it on my production queries and it shows about 5-10% performance boost. I use Relay with a lot of fragments.
I use sha256 hash of query as a key. So we may develop it further towards implementing Apollo Automatic persisted queries. While Relay currently uses md5 hashes for their Persisted queries, I guess they will change it soon to a better hashing algorithm.
Breaking changes
GraphQL::executeQuery()is deprecated and should be removed in the next version.parseAndExecuteQuery()orexecuteParsedQuery()should be used instead. This PR has a simpleexecuteQuery()stub that executes one of above methods depending on thequerytype.