简体   繁体   English

React Native:最好将大 object 存储在 AsyncStore 或本地 JSON 文件中?

[英]React Native: better to store large object in AsyncStore or local JSON file?

In my React Native app I make an API call that takes about 30s to return, because it's retrieving an object that contains about 4000 items.在我的 React Native 应用程序中,我进行了一个 API 调用,大约需要 30 秒才能返回,因为它正在检索一个包含大约 4000 个项目的 object。 I want to store that object locally so that the user has to fetch it only the first time they install, rather than every time they log in. Should I use AsyncStorage for this?我想将 object 存储在本地,这样用户只需在第一次安装时获取它,而不是每次登录时都获取它。我应该为此使用 AsyncStorage 吗? Or store it as a local JSON file on the device?或者在设备上存储为本地 JSON 文件?

There can be multiple approaches to deal with it,可以有多种方法来处理它,

If your data is dynamic, then obviously you need the API to load the data.如果您的数据是动态的,那么显然您需要 API 来加载数据。 After API calling you can store the data in either local storage or local file system API 调用后,您可以将数据存储在local storagelocal file system

local storage has a 6MB limit of default, but you can increase this limit, local storage默认有6MB的限制,但是你可以增加这个限制,

If your data size is large in size like greater than 6MB then you can use the file system to store the file, react-native-fs is the library that can help you to create and read the file to the local file system如果你的数据量很大,比如greater than 6MB那么你可以使用文件系统来存储文件, react-native-fs是可以help you to create and read the file to the local file system的库

However, if your data is not dynamic , then you can use the local JSON file to store the data, but this is will increase the.apk or.ipa size when you will upload it to the store但是,如果你的data is not dynamic的,那么你可以使用local JSON文件来存储数据,但这会增加你上传到商店时的 .apk 或 .ipa 大小

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM