13

I'm monitoring my web calls with Charles.

I have a GlideModule changing cache folder by overriding applyOption(...) like this :

    @Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(
            new InternalCacheDiskCacheFactory(context, "/media/", 1500000)
    );
}

Then, I do my Glide images loads and the cache works just fine while I'm in the app. Here is an example :

Glide.with(this)
            .load("http://www.wired.com/wp-content/uploads/2015/09/google-logo.jpg")
            .into(mImageView);

Only the first call make a web call and then it use cache to retrieve it. However, if I kill the app then relaunch it, instead of continuing to use the cache, the app make a new web call. Isn't the cache supposed to be persistent inside the Internal storage ?

Magnas
  • 869
  • 1
  • 5
  • 18

4 Answers4

1
Glide.with(fragment)
  .load(url)
  .diskCacheStrategy(DiskCacheStrategy.ALL)
  .into(imageView);
Chandan kushwaha
  • 941
  • 6
  • 26
0

Increase the diskCacheSize and see what happens. 1500000 is 1.5mb, it can contain a limited number of pictures (depending on each size). When the limit is met, old cached images will be replaced by the new ones.

So no matter how big the diskCacheSize is, when it is exceeded old cached images will be replaced by new ones.

Also note that besides 'disk Cache', Glide keeps images in memory until some conditions are met to release them (activity kill, low memory, ...). That's why it does not download the not-cached images again while the app is alive, because it accesses them through memory.

navid
  • 1,022
  • 9
  • 20
0

Yes, that is the base functionality of the glide lib it gets all their cache while downloading the image first time and then every next time it gives you the image from its cache.

if you face only face the issue then as per my opinion you should use Picasso for the image processing if your existing system does not depends on the guild.

Arpan24x7
  • 648
  • 5
  • 24
0

you can download the image and store inside the internal storage of your app using sqllite and load the image from there passing the local URL in the ".load()".

But here every time your glide getting call it's loading the image directly using the URL because you pass URL in ".load()" method, not only it will make a web call after relaunching the app, it will make web call very time glide getting call in the app, like if you using it in the recycler view.

subrata sharma
  • 344
  • 4
  • 17