问题
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