How does caching work in GraphQL?

2019-07-24 16:23发布

GraphQL works as a query language posting always against a single end point. So most caching tools can't be used. So is network caching completely impossible with GraphQL? Is client side caching the only possible way to cache? Or is there a workaround?

1条回答
我命由我不由天
2楼-- · 2019-07-24 17:14

When using HTTP transport for your GraphQL API you can cache the HTTP responses just like any other HTTP traffic. Typically the CDN will hash the full request and then cache the response with that hash. When the same request comes in next time it won't connect to your GraphQL server, it will just respond with the cached results.

The challenge with GraphQL is that it's traditionally sent via POST, which is not supported by many CDNs. You can either use GET with a normal CDN (Fastly, Cloudflare, Cloudfront), or you can use a GraphQL specific CDN (FastQL).

Full disclosure: I built FastQL after running into this issue.

查看更多
登录 后发表回答