简体   繁体   中英

cache image without showing glide

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.

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

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

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

Glide.with(context)
    .load(yourUrl)
    .diskCacheStrategy(DiskCacheStrategy.SOURCE)
    .preload();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM