如何从Glide中的磁盘缓存中删除特定的图像URL?

问题描述 投票:0回答:1

我正在从远程URL将图像加载到带有Glide的ImageView中。更新图像时,该URL中的内容会更改,但URL位置保持不变。 (这是预期的)。

例如。 https://www.the-android-app.com/userid/121.jpg

现在我使用此代码将图像显示到ImageView中。

Glide
     .with(this)
     .load(profilePicUrl) //this is in String format
     .diskCacheStrategy(DiskCacheStrategy.RESULT)
     .skipMemoryCache(true)
     .error(R.drawable.default_profile_pic)
     .into(imgProfilePic);

当我更新我的个人资料图片时,Glide正在从Cache加载相同的旧图片。我需要在获取新图像之前删除此URL的缓存条目。

编辑:网址始终保持不变,只有其中的内容发生变化。我正在使用Glide 3.8.0

android image caching android-glide
1个回答
0
投票

你可以尝试签名(new ObjectKey(System.currentTimeMillis()))

查看Custom cache invalidation了解更多信息。

GlideApp.with(this)
        .load(imageUrl)
        .signature(new ObjectKey(System.currentTimeMillis()))
        .into(imageView);
© www.soinside.com 2019 - 2024. All rights reserved.