Apollo客户端InMemory缓存的物理存储

问题描述 投票:0回答:1

根据 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/

  1. 这个内存存储物理上是在哪里创建的?是在 sessionStorage 或 localStorage 或索引数据库或前端服务器中吗?
  2. 此缓存中存储的数据的生命周期是什么?它是否会在浏览器会话关闭(如会话 cookie)或选项卡关闭(如会话存储)时被删除?
reactjs graphql apollo-client apollo-server state-management
1个回答
0
投票

InMemory Cache 作为 Apollo Client 的一个字段存在,因此具有相同的生命周期。这也意味着每个浏览器选项卡都有自己的 InMemory 缓存,并且缓存存在的时间不长于选项卡本身。

如果您想在多个选项卡之间共享缓存,可以使用“apollo3-cache-persist”库。该库旨在使用 sessionStorage 或 localStorage 等存储在不同选项卡之间同步 InMemory Cache。

相关链接:

© www.soinside.com 2019 - 2024. All rights reserved.