什么是默认的Apollo客户端查询缓存TTL?
我通过React/Next应用程序使用Apollo Client/Server使用默认缓存策略启用内存内存,我猜这是Cache-First。
我想知道什么是默认的Apollo缓存TTL?换句话说,我需要多少时间等待更新的数据才能获得客户?
试图在文档中找到此信息,但没有运气。
提前致谢。
I use Apollo Client/Server through a React/Next app with in-memory cache enabled with the default cache strategy, I guess it's cache-first.
I'd like to know what is the default Apollo cache TTL? In other words, how much time do I need to wait for the updated data to get to the client?
Tried to find this information in the documentation but no luck.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Apollo 客户端缓存及其获取策略没有“ TTL”机制或您所描述的内容。
获取策略只需告诉客户如何返回其缓存数据或提出请求 /重新呼叫请求即可。
https:///www.apolloght /data/Queries/#supported-fetch-policies
IE。 “首先缓存”,表示从缓存中返回数据,或提出获取它的请求。如果存在在缓存中,它不会提出任何请求。
-
如果您想在客户端中执行所描述的事情,则可能需要开发自己的机制。
在服务器上有一些选项:
一个示例是使用 http缓存标头(在此答案中喜欢),这是一个独立于Apollo的概念,只是一个功能但是,在浏览器,CDN等。但是,在服务器上,您可以将缓存标头提示为对象上的指令,然后告诉浏览器如何处理这些请求。 https://www.apolloght缓存
或配置自己的商店以在服务器上的缓存响应,请参见:
配置缓存后端
Apollo Client cache and it's fetching strategies don't have a 'TTL' mechanism, or what you are describing.
Fetch policies simply tell the client how to return it's cached data or make requests / re-call requests.
https://www.apollographql.com/docs/react/data/queries/#supported-fetch-policies
ie. "cache first", means returns the data from the cache, or make the request to fetch it. It won't make any request if it exists in the cache.
--
If you want to do what you're describing in the client you'll likely need to develop your own mechanism.
On the server there are a few options:
One example is using HTTP cache headers (like in this answer), which is a concept independent of Apollo and just a feature of browsers, CDNs, etc. But on the server you can set cache header hints as directives on your objects which then tell the browser how it should handle those requests. https://www.apollographql.com/docs/apollo-server/performance/caching
Or configuring your own store for caching responses on the server, see:
Configuring cache backends
默认最大年龄为零
,因为每个GraphQL操作都包含一个根字段,这意味着默认情况下,除非设置高速缓存提示,否则任何操作结果都不会缓存!
< -Server/performance/caching/#default-maxage
Default max age is zero
Because every GraphQL operation includes a root field, this means that by default, no operation results are cached unless you set cache hints!
https://www.apollographql.com/docs/apollo-server/performance/caching/#default-maxage
在寻找它之后,我终于找到了它。
Apollo服务器的默认内存商店没有TTL,查询将永远缓存,直到它们被覆盖为止。但是,对于所有其他受支持的商店,默认情况下,现场直播的时间设置为300秒。
https:https:// wwwwww .apollographql.com/docs/apollo-server/performance/apq/#adjusting-cache-time-to-live-ttl
After looking for it too I finally found it.
Apollo Server's default in-memory store does not have a TTL, the queries stay cached forever until they're overwritten. However, for all other supported stores, the time to live is set to 300 seconds by default.
https://www.apollographql.com/docs/apollo-server/performance/apq/#adjusting-cache-time-to-live-ttl