【问题标题】:Why my Glide doesn't cache the image ? it seems download image all over again为什么我的 Glide 不缓存图像?似乎重新下载图像
【发布时间】:2019-03-24 21:11:28
【问题描述】:

我正在尝试使用以下代码下载图像:

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

但结果是这样的,在这个视频中:https://drive.google.com/file/d/1ljGxwsi0wpaZbBY_CLmczdBzD9krz4QQ/view?usp=sharing

当我向下滚动到回收器视图的底部,然后返回顶部时,第一个图像消失了,似乎重新下载了图像

我尝试将 diskStartegy 删除为如下所示:

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

但结果是一样的。我在我的 gradle 文件中使用它

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

【问题讨论】:

    标签: android android-glide


    【解决方案1】:

    将你的diskCacheStrategy从DiskCacheStrategy.AUTOMATIC更改为DiskCacheStrategy.onlyRetrieveFromCache(true),这只会在图像缓存失败时尝试发送请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-23
      • 2021-05-30
      • 1970-01-01
      • 2017-02-06
      • 2017-07-01
      • 1970-01-01
      相关资源
      最近更新 更多