Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent/Offline Image cache in Android

I am trying to figure out the best and the most efficient way of caching images to the disk, such that they would persist even after app is killed and re-launched in airplane mode. Consider the following use case:

  1. Open the app and get all images and display them in their respective ImageView's
  2. Kill the app
  3. Put device in air plane mode
  4. Open the app again.

I am trying to get the images to persist in an offline cache so that they can be displayed in the scenario mentioned above.

I went through documentation for picasso and glide and it wasn't exactly clear if their disk caching would work in this case.

Is there a way to do this using picasso or glide? I am trying to avoid having to write a custom implementation for storing this in SQLite etc.

like image 299
snoopyCache Avatar asked Sep 26 '26 08:09

snoopyCache


1 Answers

Glide will do this for you by default without any extra work on your side. You can also customize what versions of the requested image to store in the cache.

One important thing you need to consider is if the URLs that you use Glide to fetch images from are available offline otherwise you will need to have some way to cache those as well so that you can initiate the Glide calls when you are offline.

You can see how I did it in this project: https://github.com/KhalafMH/popular-movies-android.git

To read about how to configure Glide caching see:
http://bumptech.github.io/glide/doc/caching.html

like image 132
Mahdi AlKhalaf Avatar answered Sep 27 '26 22:09

Mahdi AlKhalaf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!