5

Is it possible to cache image using glide without showing it in the imageView?. If it is then how?.

Right now I'm doing this code:

Glide
  .with(getApplicationContext())
  .load("imageUrl")                
  .override(windowWidth(),(int)windowWidth()*0.5))
  .diskCacheStrategy(DiskCacheStrategy.ALL);

But this is not working , when app is open glide load image not from cache but from url.

Ajeet Choudhary
  • 1,969
  • 1
  • 17
  • 41

3 Answers3

9

Since glide 4.X:

//to save img
RequestManager rm = Glide.with(context);
rm.load(imgUrl).submit();

//to load img
Glide.with(context)
    .applyDefaultRequestOptions(
        new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL))
    .load(imgUrl)
    .into(view);

Based on this GitHub topic

Ljdawson
  • 12,091
  • 11
  • 45
  • 60
6

i've never used it, but referring the documentation: have you tried the downloadOnly?

Glide's downloadOnly() API allows you to download the bytes of an image into the disk cache so that it will be available to be retrieved later.

https://github.com/bumptech/glide/wiki/Loading-and-Caching-on-Background-Threads#downloadonly

BenRoob
  • 1,662
  • 5
  • 22
  • 24
4

To preload remote images and ensure that the image is only downloaded once:

Glide.with(context)
    .load(yourUrl)
    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
    .preload();
ucMedia
  • 4,105
  • 4
  • 38
  • 46