Jay Donga
Jay Donga

Reputation: 431

How to remove a particular image URL from disk cache in Glide?

I am loading an image from remote URL into an ImageView with Glide. When I update the image, the content within that URL changes, but the URL location remains same. (This is as expected).

for eg. https://www.the-android-app.com/userid/121.jpg

Now I am showing image into ImageView using this code.

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

When I update my profile pic, Glide is loading the same old pic from Cache. I need to remove cache entry for this URL before fetching the new image.

Edit: The url always remains same, only the content inside it changes. I'm using Glide 3.8.0

Upvotes: 1

Views: 1264

Answers (1)

librushi
librushi

Reputation: 91

You can try signature(new ObjectKey(System.currentTimeMillis()))

Look in Custom cache invalidation for more information.

Example

GlideApp.with(this)
        .load(imageUrl)
        .signature(new ObjectKey(System.currentTimeMillis()))
        .into(imageView);

Upvotes: 2

Related Questions