我注意到,当我在客户端本地更新我的缓存时,它路由到另一个页面,缓存与数据一起持久存在。
但是,当我刷新该页时,缓存被清除。有没有一种方法可以在刷新后保持缓存状态?
发布于 2019-02-13 12:32:55
阿波罗的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更友好。
https://stackoverflow.com/questions/54660710
复制相似问题