#[apollo-cache-persist] purged cached data | apollo-cache-persist Error | apollo-cache-persist not working

北城以北 提交于 2021-01-07 02:36:51

问题


This is the code I have used for cache persistance using 'apollo3-cache-persist', seems to have automatically purge the cached data after initial caching. Purging causes everything in the storage used for persistence to be cleared. Hence resulting in not persisting.

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')
  );
})

回答1:


Maximum size of cache to persist when using 'apollo3-cache-persist' (in bytes) Defaults to 1048576 (1 MB). ie if this exceeds then persistence will pause and app will start up cold on next launch.

  • maxSize?: number | false,

Therefore For unlimited cache size, provide false.

persistCache({
  cache,
  storage: new LocalStorageWrapper(window.localStorage),
  debug: true,
  maxSize: false
})
  .then(() => { 
  ...
})


来源:https://stackoverflow.com/questions/65506967/apollo-cache-persist-purged-cached-data-apollo-cache-persist-error-apollo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!