0

I need to store localisated data from the web, which comes in a JSON string. So far I have a DataAdapter which expects data in a JSONObject and collectes the data for visualisation. But now I have no caching at all.

I want to store the data from the last call including a Etag for observing changes. So I want to show at first the cached data and look on the web if there are some changes and show them as far they are aviable. I see there three options:

  • Plain storage of the whole JSON in a file
  • Storage of the data in a SQLite database
  • Using a CouchDB for Android

I'm not sure which way is most efficency... I want also to store/cache images. By the way I also want that the data are encrypted so far the storage system must not write any data directly on the flash memory, when seconds later comes another bound of data. And also I want to save the battery.

Which is the most energy efficency way to store data?
Which is the fastes way to store data?

rekire
  • 47,260
  • 30
  • 167
  • 264
  • There is a bunch of information about how to make the most efficient use of caching and the network when making an app on the AT&T developer site http://developer.att.com/developer/forward.jsp?passedItemId=7200042 – Rod Burns Nov 05 '12 at 13:46
  • This is a really good ressource, but I know most stuff from that page... If you could post a link about caching on the client side I would be happy to accept such a link as an answer. – rekire Nov 05 '12 at 15:18

2 Answers2

0

For small web-service requests you can use ResponseCache. When dealing with larger objects you might want to create your own cache.

You could also:

  • Serialize the data and save it to a local file
  • For basic data you could save it in SharedPreferences if it is meant to be stored for a longer period
  • Use sqlite if you have a large amount of data and you need to perform relational operations on it.

For image caching, see:

Android image caching

Android: Image cache strategy and memory cache size

Community
  • 1
  • 1
Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84
  • Caching data into the browser cache looks like an interessting idea but I cannot use the `URL` class because it does not support the ntlm auth scheme. However I want to encrypt the stored data and none of your links seems to provide a encryption support. I saw in one refered question the `SoftReference` class looks very helpful. thx – rekire Nov 02 '12 at 12:05
0

My solution was to extends a LruCache where I override the sizeOf function to get the real size.

For Drawables I use this code:

if(rawdata  instanceof BitmapDrawable) {
    Bitmap bmp = ((BitmapDrawable)rawdata).getBitmap();
    mem += bmp.getRowBytes() * bmp.getHeight();
}
rekire
  • 47,260
  • 30
  • 167
  • 264