LocalStorage或SQLite数据库? [英] LocalStorage or SQLite Database?
问题描述
我目前正在开发一个移动应用程序,该应用程序使用AJAX请求从服务器获取数据.
I'm currently developing a mobile application which uses AJAX request to get data from a server.
要在我的应用程序中启用脱机导航,我需要存储所有收集的数据.
To enable offline navigation in my application, I need to store all data collected.
我的应用程序功能非常强大,因为有一个部分可供用户查看图表(由图表高位驱动).
My application is quite powerful because there's a section where the user can see charts (powered by highcharts).
我在问自己关于缓存以JSON格式收集的数据的最佳解决方案.
I'm asking myself about the best solution to cache the data collected in the JSON format.
将数据阵列JSON.stringify
放入本地存储中足够轻巧或高效:
Is it light or efficient enough to JSON.stringify
the data array into local storage like:
localStorage.setItem("graph_1_datas", JSON.stringify(json_data_array));
或者创建一个数据库和一个像这样的表会更好:
Or would it be better to create a database, and a table like that:
TABLE
-----
id
graphId
blockId
x
y
我按blockId有3个graphId,还有大约10个blockId ...
I have 3 graphIds by blockId, and about 10 blockIds...
推荐答案
将JSON字符串存储到本地存储应该是相当快速和有效的.只需为每个请求存储一个单独的文件,然后它将为您提供清晰的简单代码,用于从本地存储或Web服务获取数据.
Storing the JSON strings to local storage should be fairly fast and efficient. Just store a separate file for each request and then it will give you clear simple code for getting the data either from local storage or web service.
如果您可能想脱机编辑数据,则不妨考虑使用SQLite数据库,因为它将使添加代码来跟踪更改更容易/更有效.
If you are likely to want to edit the data offline then you may wish to consider an SQLite database as it will make it easier/more efficient to add code to track changes.
如果您的对象图变得更加复杂并且适合关系数据库模型,则您可能还需要考虑使用SQLite数据库.
You may also want to consider an SQLite database if your object graph gets more complicated and fits a relational database model.
这篇关于LocalStorage或SQLite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!