Blueadd
Blueadd

Reputation: 13

FirebaseUI with glide and cache

I do not quite understand how the recyclerView and glide work with regards to caching information and image data so I was wondering if anybody could help.

Currently I store meta-data about my images in the realtime database. The meta-data has enough information to be able to make a storage reference and pull the correct image from the database:

storageReference.child("users/uid/profile.png")

However, my question is regarding the firebaseUI element:

Glide.with(this)
    .using(new FirebaseImageLoader())
    .load(storageReference)
    .into(imageView);

So I add to images to my recyclerview as follows:

for (ProfileCard card : localDB.getAllCards()) {
   profileCards.add(1, card);
   adapter.notifyItemInserted(1);
}

Now everytime I leave this activity where the cards reside the activity is obviously destroyed. In the onCreate of the class the for loop is called again. So when I do adapter.notifyItemInserted(1); the adapter will be called and the glide function for adding the picture will be called again.

So my question is everytime I destroy and re-create the activity and then add the cards again when the glide method is called does it make a request to the storage bucket to download the image again? If not what happens? and if the images are stored in cache how big is this cache?

Any help is much appreciated

Upvotes: 1

Views: 643

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317392

Many of your answers about Glide can be answered if you read through the project wiki on GitHub.

When Glide fetches an image, it will be cached locally in memory and on disk. You can configure the sizes of these caches. Here's what the documentation has to say about the default disk cache size:

The internal cache factory places the disk cache in your application's internal cache directory and sets a maximum size of 250MB.

And for the memory cache:

Default sizes are determined by the MemorySizeCalculator class. The MemorySizeCalculator class takes into account the screen size available memory of a given device to come up with reasonable default sizes.

It's expected that things will be built up and torn down repeatedly. That's why these caches exist.

Upvotes: 1

Related Questions