LocalStorage or SQLite Database?

亡梦爱人 提交于 2019-12-14 02:35:45

问题


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).

I'm asking myself about the best solution to cache the data collected in the JSON format.

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

I have 3 graphIds by blockId, and about 10 blockIds...


回答1:


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.

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.

You may also want to consider an SQLite database if your object graph gets more complicated and fits a relational database model.



来源:https://stackoverflow.com/questions/7038122/localstorage-or-sqlite-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!