根据 Apollo Client 文档,InMemory 缓存用于 apollo 客户端缓存,如下面的代码所示
import { InMemoryCache, ApolloClient } from '@apollo/client';
const client = new ApolloClient({
// ...other arguments...
cache: new InMemoryCache(options)
});
参考:https://www.apollographql.com/docs/react/caching/cache-configuration/
InMemory Cache 作为 Apollo Client 的一个字段存在,因此具有相同的生命周期。这也意味着每个浏览器选项卡都有自己的 InMemory 缓存,并且缓存存在的时间不长于选项卡本身。
如果您想在多个选项卡之间共享缓存,可以使用“apollo3-cache-persist”库。该库旨在使用 sessionStorage 或 localStorage 等存储在不同选项卡之间同步 InMemory Cache。
相关链接: