This example demonstrates how we can cache the response fragments in graphql-ruby.
Existing solutions only allow caching resolved values but not all the GraphQL machinery (validation, coercion, whatever).
Caching response parts (in case of Ruby, sub-Hashes) is much more efficient.
For a simple query with one loaded associations and a few simple fields (running schema.execute
):
Calculating -------------------------------------
with cache 225.227 (± 9.3%) i/s - 1.122k in 5.035785s
with no cache 135.870 (±11.0%) i/s - 672.000 in 5.025641s
Comparison:
with cache: 225.2 i/s
with no cache: 135.9 i/s - 1.66x slower