这是我使用'apollo3-cache-persist'用于缓存持久性的代码,似乎在初始缓存后自动清除缓存的数据。清除会清除存储中用于持久性的所有内容。因此导致不坚持。
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')
);
})