views:

33

answers:

1

I'm building an app that retrieves a JSON dataset from a PHP server. The app has a view that displays a "feed" of several different newly added or updated items from the web server.

The app loads 20 of the newest items to start with, and the user can subsequently load 20 more older items, and 20 more, and so on. I want this data to persist between subsequent view changes, and quitting/launching the app.

So far I have a PHP webservice handling the JSON response by accepting a last_updated timestamp, which is sent by the iphone client with the webservice query. The server then returns any items it finds that are newer than the last_updated time.

On the iPhone side I have the connection to the webservice returning results to the iphone and displaying them in custom UITableViewCell cells. However as of right now the app will request the data from the webservice every single time.

I'm a little confused as to what's a good way to cache this data. Do I store the actual cells themselves, or create an object for each feed item type and store that? Or something else? Do I use core storage, sqlite, or some other custom method?

Thanks for any insight.

+2  A: 

You never store data of any kind in a table view cell. Cells are intended to be reused to create the illusion of an arbitrarily long table. If you keep creating and retaining the cells as a data store you will eat all your memory very quickly.

It sounds like you do want to create a Core Data store although a plist and SQL are inferior options. The learning curve for Core Data is relatively steep but once you learn it it makes everything easier.

TechZen
If I use Core Data would I have to essentially re-create the same data model structure as my MySQL db?
Calvin L
Probably, but it depends on what you're trying to do and how complex the data is. If you want to just save the individual JSON request you save them individual into plist files. If the data has a lot of relationships it would be best to use Core Data. I don't really have enough info to really advise in detail.
TechZen
Good to know, thanks. The data does indeed have a lot of relationships. This is gonna be tough!
Calvin L