页面刷新时,apollo-state-link不在缓存中保持状态

时间:2019-02-13 00:26:24

标签: react-apollo next.js apollo-link-state

我注意到,当我在客户端本地更新缓存并将其路由到另一个页面时,缓存将与数据一起保留。

但是,当我刷新该页面时,将清除缓存。有没有办法即使刷新后仍保持缓存状态?

1 个答案:

答案 0 :(得分:0)

Apollo的InMemoryCache很好地在内存中,因此在页面加载之间不会持久存在。推荐的持久化缓存的方法是使用apollo-cache-persist。用法示例:

import { InMemoryCache } from 'apollo-cache-inmemory'
import { persistCache } from 'apollo-cache-persist'

const cache = new InMemoryCache({...})

persistCache({
  cache,
  storage: window.localStorage,
});

const client = new ApolloClient({
  cache,
  // other client options
})

有关高级配置和用法,请检查存储库。另外,请注意,如果您使用的是SSR,则有known issues个正在使用此库。您还可以结帐apollo-cache-instorage,这可能对SSR更为友好。

相关问题