I am using
glide.load(url)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.preload()
to preload images.
However, I need them to be in memory and not just on disk, so it's loaded in ImageView
more quickly, the way it does when I revisit the images after loading them in ImageView
once.
I have also tried
glide.load(url)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(PreloadTarget.obtain(glide, PreloadTarget.SIZE_ORIGINAL, PreloadTarget.SIZE_ORIGINAL))
without much luck.
PS: I have visited this question and others, answers are outdated hence this question.
Glide will put all image resources into the memory cache by default.
Disk Cache Strategies The available strategies allow you to prevent your load from using or writing to the disk cache or choose to cache only the unmodified original data backing your load, only the transformed thumbnail produced by your load, or both.
Referring to this article you can cache the image in the memory then use
onlyRetrieveFromCache( true )
to load the image only from memory
In order to get cached resource from the memory cache, loaded objects should be exactly equal. Read in docs here. To verify if your preloaded object and object loaded to ImageView are the same enable Glide logs for the Engine class.
adb shell setprop log.tag.Engine VERBOSE
Then compare the EngineKey objects that you see in logs for preload and for actual load to ImageView. They should not only have the same url and signature, but also transformations and options.
In case you load into ImageView, to not add any transformation based on ImageView params, use the
RequestOptions().dontTransform()
for the load to ImageView request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With