什么是默认的Apollo客户端查询缓存TTL?

发布于 2025-02-11 19:05:40 字数 172 浏览 1 评论 0原文

我通过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南汐寒笙箫 2025-02-18 19:05:40

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

风铃鹿 2025-02-18 19:05:40

默认最大年龄为零

,因为每个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

如此安好 2025-02-18 19:05:40

在寻找它之后,我终于找到了它。
Apollo服务器的默认内存商店没有TTL,查询将永远缓存,直到它们被覆盖为止。但是,对于所有其他受支持的商店,默认情况下,现场直播的时间设置为300秒。

https:https:// wwwwww .apollographql.com/docs/apollo-server/performance/apq/#adjusting-cache-time-to-live-ttl

Apollo服务器的默认内存商店未指定APQ的TTL(APQ一直缓存,直到被Cache的标准驱逐策略覆盖为止)。对于所有其他受支持的商店,默认的TTL为300秒。您可以通过设置Persistedqueries选项的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

Apollo Server's default in-memory store does not specify a TTL for APQs (an APQ remains cached until it is overwritten by the cache's standard eviction policy). For all other supported stores, the default TTL is 300 seconds. You can override or disable this value by setting the ttl attribute of the persistedQueries option, in seconds:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文