这是我使用‘apollo3- cache - persistance’进行缓存持久化的代码,似乎在初始缓存之后自动清除了缓存的数据。清除会清除存储中用于持久化的所有内容。因此导致不能持久。
import { persistCache, LocalStorageWrapper, LocalForageWrapper } from
'apollo3-cache-persist';
const httpLink = createHttpLink({
uri: 'http://localhost:4000/'
});
const cache = new InMemoryCache();
persistCache({
cache,
storage: new LocalStorageWrapper(window.localStorage),
debug: true,
})
.then(() => {
const client = new ApolloClient({
link: httpLink,
cache,
connectToDevTools: true
});
ReactDOM.render(
<ApolloProvider client={client}>
<BrowserRouter>
<App />
</BrowserRouter>
</ApolloProvider>
,
document.getElementById('root')
);
})发布于 2020-12-30 20:34:16
使用'apollo3- cache - persist‘时要保留的最大缓存大小(以字节为单位)默认为1048576 (1 MB)。也就是说,如果超过这个值,那么持久性将暂停,应用程序将在下一次启动时冷启动。
因此,对于无限制的缓存大小,请提供false。
persistCache({
cache,
storage: new LocalStorageWrapper(window.localStorage),
debug: true,
maxSize: false
})
.then(() => {
...
})https://stackoverflow.com/questions/65506967
复制相似问题