I'm afraid the Firebase SDK does not provide image caching on its own. But there are some great libraries that could do this for you. They upload an image, display it in an ImageView, and cache it in a single line of code. Just request Firebase for the image upload URL and submit it to the image caching library.
Something like this if you select Picasso as your caching library:
storageRef.child("users/me/profile.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() { @Override public void onSuccess(Uri uri) { // Got the download URL for 'users/me/profile.png' // Pass it to Picasso to download, show in ImageView and caching Picasso.with(context).load(uri.toString()).into(imageView); } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception exception) { // Handle any errors } });
UPD: To use disk caching using Picasso, you need to explicitly configure OkHttpDownloader. Look here. How to use disk caching in Picasso?
Aleksei Reshetnikov
source share