Android REST Services – Should Data Be Stored Locally?

androiddatabaseprogramming practicesrest

Let's say I have an application that has constantly changing data. Changes are so frequent that you basically need to refresh data every time you open some screen and keep refreshing it. Is it worth implementing local database for such application?

Implementing database in such application seems redundant because:

  • Data structure might be complex (arrays, optional parameters and etc) and so using cursors is not a very efficient way to pass it around
  • Data does not need to be stored for long time
  • If optimized to request filtered data in certain screens (to reduce data traffic), must make sure to filter database updates in such way that unfiltered data (which might be used by other screens) is not affected. Not that hard but still something to develop (and test)

However, implementing local database might mean faster navigation. But again, that's not true if service requests are highly optimized to avoid sending redundant data.

Do applications like Play Store, Facebook, Google+ use local database to replicate data structures stored in remote database? I just wanna know what is the common practice for developing applications heavily based on web services.

Best Answer

as long as

  • it is ok that the app does not work when there is no networkconnection available (similar to a web-page)
  • your app does not need to store additional info like "user has seen this info at 15:30"

you donot need to implement a cache.

if you want to cache the data for faster access why putting it into a database with complex datastructure?

isnt it enough to save every service result as one file where the search-parameters create the filename (i.e. based on the rest-url)?

a webbrowser stores raw html/gif/css files instead of analysing it and storing in tables like page, link, caption, ....

you should already have a serialisation format for the transportation from service to android client (JSON, XML, ....) why not using this format for the file cache, too

Related Topic