0

这是我使用'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')
  );
})
4

1 回答 1

0

使用 'apollo3-cache-persist' 时要保留的最大缓存大小(以字节为单位) 默认为 1048576 (1 MB)。即,如果超过这个值,那么持久性将暂停,应用程序将在下次启动时冷启动。

  • 最大尺寸?:数字 | 错误的,

因此,对于无限缓存大小,请提供 false。

persistCache({
  cache,
  storage: new LocalStorageWrapper(window.localStorage),
  debug: true,
  maxSize: false
})
  .then(() => { 
  ...
})
于 2020-12-30T12:34:15.783 回答