#[apollo-cache-persist]清除了缓存的数据|apollo-cache-persist错误|阿波罗缓存持久化器不起作用 [英] #[apollo-cache-persist] purged cached data | apollo-cache-persist Error | apollo-cache-persist not working
问题描述
这是我使用'apollo3-cache-persist'进行缓存持久化的代码,它似乎在初始缓存后自动清除了缓存的数据.清除会清除存储中用于持久性的所有内容.因此导致不持久.
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')
);
})
推荐答案
使用'apollo3-cache-persist'时要保留的最大缓存大小(以字节为单位)默认值为1048576(1 MB).也就是说,如果超过此限制,则持久性将暂停,并且应用程序将在下次启动时冷启动.
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 ?:数字|错误,
因此,要获得无限的缓存大小,请提供false.
Therefore For unlimited cache size, provide false.
persistCache({
cache,
storage: new LocalStorageWrapper(window.localStorage),
debug: true,
maxSize: false
})
.then(() => {
...
})
这篇关于#[apollo-cache-persist]清除了缓存的数据|apollo-cache-persist错误|阿波罗缓存持久化器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!