简体   繁体   中英

Best way to store dyamic data on iOS App from Web Service


I want to know what is the best way to store data on the iPhone from a web service. I want the information to be stored on the device so the person doesn't need to access the web service every time he/she needs it. The currently information isn't much and contains less that 150 records. The records might update from time to time and a few new ones will be added. What is the best way to go about storing the data?

Thanks

If you use ASIHTTPRequest for your network stuff (and if you don't already, I can't sing its praises highly enough), you will find it has a cache layer built in which is perfect for situations like this.

You can activate it with a simple one line;

[ASIHTTPRequest setDefaultCache:[ASIDownloadCache sharedCache]];

And you have full control over the cache policy etc - just read the documentation.

The other simple approach of course is - on the assumption that your web service is returning JSON or XML - simply to store the response in a local file against a hash of the request parameters, then when you request the data again, you can first look to see if the file exists and if it does, return that data rather than going back to the website. You can roll your own cache policies etc too.

Since I discovered ASIHTTPRequest had a cache though, I've not needed to roll my own again.

I find that using coreData or sqllite3 is just overkill for 99% my requirements and a simple cache works very well.

If the data is relational, a Sqlite3 database would be the best storage option you have.

Also, this helps by allowing you to retrieve from the server and to update only the records that have changed, thus saving time and bandwidth.

This is the best option from a scalability point of view as well, as you stated that "current information isn't much", thus giving the impression that this is only a current situation, that may be subjected to further change, probably towards more records being added in time.

Sqite3 also gives you more control and better performance than using, for instance, Core Data. Here 's an article explaining some of the details. Moreover, if you work through an Objective-C wrapper, such as FMDB , you get all the advantages without managing the complexity yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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