-1

I have an app where I take data from API (some points on map with properties like descriptions, lan, lat, and list of photos) because of offline mode. I am not sure if I should use sharedPreferences or some okHttp cache (or some ORM database). SharedPref is good for small values, not for list of objects. Do you have suggestions/best practices?

Thanks

Stepan
  • 1,041
  • 5
  • 23
  • 35

2 Answers2

0

Store your data in db with image URIs. Store Images in memory cache and retrieve them from their URI. Retrofit doesn't comes with support for image loading from network by itself. If you don't want to go into depth of all this, you can use Glide or Picasso.

Picasso saves full image and can be resized at the time of loading. Glide caches images after resizing. See what fits your case.

Storing and retreiving images directly from database will require too much processing and slow down loading of images especially if you need large images. For more information read check out developers note on Caching Bitmaps and Display Bitmaps Efficiently.

Imdad
  • 683
  • 1
  • 9
  • 27
  • What OP issue ? He want info about Share prefernce and OKHTTP cache – sushildlh Aug 26 '16 at 11:02
  • @sushildlh Picasso uses OkHttp and Shared Preferences are not recommended for storing images. I was trying to put a general answer. – Imdad Aug 26 '16 at 11:08
  • OkHttp cache are used for storing images . will you ever used OKHTTP cache ? – sushildlh Aug 26 '16 at 11:11
  • 1
    @sushildlh No sir, I never said that. OkHTTP caches network response. But Picasso caches images and uses OkHTTP as its network stack. Thats why my answer doesn't mentions OkHTTP anywhere for images. – Imdad Aug 26 '16 at 11:21
  • I think OP wants to store every thing on the cache that's why he confused about cache and share Preference.Every thing means image and data .....So it is not good idea to implement Picasso for Image and Data to cache. – sushildlh Aug 26 '16 at 11:25
  • I have explained that i my answer – Imdad Aug 26 '16 at 11:28
  • My question was more about data, not only pictures (I use Picasso). – Stepan Aug 26 '16 at 11:41
  • 1
    @Stepan for data use sqlite, it will keep your data structured. Shared prefs are difficult manage for large amount of data. But better than all this confusion use Realm. Simple, easy and fast! – Imdad Aug 26 '16 at 11:45
  • Thanks, that's what I need. – Stepan Aug 26 '16 at 11:49
0

I would suggest you to use response cache if you require the response only to display. Retrofit provides a nice and handy response caching method, you can make use of Interceptors to cache response. hope you are using retrofit latest version 2.1.0. check out this link to get more.

If you wanted to perform some operations like marking favourites etc. you can go for database.

Community
  • 1
  • 1
droidev
  • 7,352
  • 11
  • 62
  • 94