Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide preload doesn't save in cache

I would like to preload images before they are showed to the user. I have a ViewPager where every page is an image. When the activity starts, it calls:

Glide.with(this).load(uri).preload();

After that all the images are preloaded (theoretically), in order to test if the preload works, I disable all network connections and I try to swype between the pages to load the images, but Glide doesn't load them.

In my project, Glide is configured with default values.

Furthermore, if I load the image swyping the viewpager (with internet connection), Glide saves the images in cache.

I tried also using

Glide.with(this).load(uri).downloadOnly(x,y);

with the same results.

like image 727
fran Avatar asked Jan 11 '16 11:01

fran


People also ask

Does glide cache images by default?

By default, Glide uses memory and disk caching to avoid unnecessary network calls, it checks into multiple layers of caches before initiating a new request call for an image.

How do you cache images on Glide?

How Glide Cache Works. By default, Glide checks multiple layers of caches before starting a new request for an image: Active resources — Is this image displayed in another View right now? Memory cache — Was this image recently loaded and still in memory?

Can I delete glide cache?

Deleting cached images Glide does not automatically purge cached images. However, this can be done by your application using the deleteCache() method.


1 Answers

I solved the problem by myself adding the diskCacheStrategy.

Glide.with(this)
     .load(uri)
     .diskCacheStrategy(DiskCacheStrategy.SOURCE)
     .preload();
like image 136
fran Avatar answered Sep 22 '22 00:09

fran