如何解决#[apollo-cache-persist] 清除缓存数据 | apollo-cache-persist 错误 | apollo-cache-persist 不工作
这是我使用 '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')
);
})
解决方法
使用“apollo3-cache-persist”时要持久化的最大缓存大小(以字节为单位)默认为 1048576 (1 MB)。即如果超过,则持久性将暂停,应用程序将在下次启动时冷启动。
- maxSize?: number |假的,
因此对于无限缓存大小,请提供 false。
persistCache({
cache,storage: new LocalStorageWrapper(window.localStorage),debug: true,maxSize: false
})
.then(() => {
...
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。