'Glide: Preload images in memory cache (with or without disk cache)
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.
Solution 1:[1]
Referring to this article you can cache the image in the memory then use
onlyRetrieveFromCache( true )
to load the image only from memory
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mohammad Sommakia |
| Solution 2 | A. Kazarovets |
