infinityloop-dev / graphpinator-persisted-queries
模块,用于在缓存中持久化验证过的查询并提高重复查询的性能。
v1.3
2023-11-10 17:23 UTC
Requires
- php: >=8.1
- infinityloop-dev/graphpinator: ^1.6
- infinityloop-dev/utils: ^2.3
- psr/simple-cache: ^3.0.0
Requires (Dev)
- infection/infection: ^0.27
- infinityloop-dev/coding-standard: ^0.2
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.4
This package is auto-updated.
Last update: 2024-09-01 04:50:07 UTC
README
⚡🌐⚡ 模块,用于在缓存中持久化验证过的查询并提高重复查询的性能。
简介
此模块允许 GraPHPinator 在服务器上缓存查询以减少服务器负载。该模块旨在通过缓存和重用已知请求来减少 GraphQL 的解析和验证开销。
请注意,此模块不会影响您的解析函数的速度。
安装
使用 composer 安装包
composer require infinityloop-dev/graphpinator-persisted-queries
如何使用
- 实现
\Psr\SimpleCache\CacheInterface
您需要一个实现 \Psr\SimpleCache\CacheInterface 的类,其中存储了请求的序列化版本以供以后重用。
- 将
PersistedQueriesModule注册为 GraPHPinator 模块
$persistModule = new \Graphpinator\PersistedQueriesModule\PersistedQueriesModule($schema, $cacheImpl); $graphpinator = new \Graphpinator\Graphpinator( $schema, $catchExceptions, new \Graphpinator\Module\ModuleSet([$persistModule, /* possibly other modules */]), $logger, );
- 您已设置完毕,查询将自动缓存在指定的存储中。
性能改进
简单的基准测试(代码在 bench 目录中)显示 GraphQL 开销大约减少了 80%。
基准测试运行相同的查询 10k 次,之前有 5 次预热查询。使用的缓存是一个简单的本地 Redis 实现,连接是通过 php-redis 扩展完成的。Opcache 已禁用。