GraphQL中的缓存如何工作? [英] How does caching work in GraphQL?

查看:71
本文介绍了GraphQL中的缓存如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GraphQL始终作为针对单个端点的查询语言发布.因此,大多数缓存工具无法使用.那么使用GraphQL完全不可能进行网络缓存吗?客户端缓存是缓存的唯一可能方法吗?还是有解决方法?

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?

推荐答案

为GraphQL API使用HTTP传输时,您可以像其他任何HTTP流量一样缓存HTTP响应.通常,CDN将散列整个请求,然后使用该散列来缓存响应.下次再次出现相同的请求时,它将不会连接到您的GraphQL服务器,它将仅以缓存的结果作为响应.

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.

GraphQL的挑战在于,传统上它是通过POST发送的,许多CDN都不支持.您可以将GET与普通CDN一起使用(快速 Cloudflare Cloudfront ),也可以使用GraphQL特定的CDN( FastQL ).

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).

全部披露:遇到此问题后,我构建了FastQL.

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

这篇关于GraphQL中的缓存如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆