Why my Glide doesn't cache the image ? it seems download image all over again

烂漫一生 提交于 2019-12-11 18:49:54

问题


I am trying to download image using the code below:

Glide.with(recommendedEventViewHolder.itemView)
            .load(currentEvent.posterDownloadPath)
            .diskCacheStrategy( DiskCacheStrategy.AUTOMATIC )
            .into(recommendedEventViewHolder.posterImageView)

but the result is like this, in this video: https://drive.google.com/file/d/1ljGxwsi0wpaZbBY_CLmczdBzD9krz4QQ/view?usp=sharing

when I scroll down to the bottom of recycler view, and then go back to the top, the first image disappear and it seems re download the image

I have tried to remove the diskStartegy to be something like this:

Glide.with(recommendedEventViewHolder.itemView)
                .load(currentEvent.posterDownloadPath)
                .into(recommendedEventViewHolder.posterImageView)

but the result is just the same. I am using this in my gradle file

implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

回答1:


Change your diskCacheStrategy from DiskCacheStrategy.AUTOMATIC to DiskCacheStrategy.onlyRetrieveFromCache(true), this will only try to send request only if images failed to cache.



来源:https://stackoverflow.com/questions/55084585/why-my-glide-doesnt-cache-the-image-it-seems-download-image-all-over-again

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!