为什么我的Glide不缓存图像?似乎重新下载了图像 [英] Why my Glide doesn't cache the image ? it seems download image all over again
问题描述
我正在尝试使用以下代码下载图像:
I am trying to download image using the code below:
Glide.with(recommendedEventViewHolder.itemView)
.load(currentEvent.posterDownloadPath)
.diskCacheStrategy( DiskCacheStrategy.AUTOMATIC )
.into(recommendedEventViewHolder.posterImageView)
但在此视频中结果是这样的: https://drive.google.com/file/d/1ljGxwsi0wpaZbBY_CLmczdBzD9krz4QQ/view?usp=sharing
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
我试图将diskStartegy删除为类似这样的内容:
I have tried to remove the diskStartegy to be something like this:
Glide.with(recommendedEventViewHolder.itemView)
.load(currentEvent.posterDownloadPath)
.into(recommendedEventViewHolder.posterImageView)
但是结果是一样的.我在gradle文件中使用了它
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'
推荐答案
将diskCacheStrategy从DiskCacheStrategy.AUTOMATIC
更改为DiskCacheStrategy.onlyRetrieveFromCache(true)
,这仅在图像无法缓存时才尝试发送请求.
Change your diskCacheStrategy from DiskCacheStrategy.AUTOMATIC
to DiskCacheStrategy.onlyRetrieveFromCache(true)
, this will only try to send request only if images failed to cache.
这篇关于为什么我的Glide不缓存图像?似乎重新下载了图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!