so i use glide everywhere in my app to upload the user's profile image via url. When the user changes their profile picture. I update the backend, so the url is updated. But, glide has cached the old image. How do i overwrite the previous cached image, so that when the user navigates through the app, he/she can see their profile picture change in all activities?
RequestOptions requestOptions = new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.NONE) // because file name is always same
.skipMemoryCache(true);
Glide.with(this)
.load(photoUrl)
.apply(requestOptions)
.into(profile_image);
In the latest versions we should use RequestOptions
RequestOptions Provides type independent options to customize loads with Glide in the latest versions of Glide.
Make a RequestOptions Object and use it when we are loading the image.
Call Glide.get(context).clearDiskCache() on outside the UI thread. (also consider clearMemory() too to prevent surprises after clearing disk cache)
Read Cache invalidation, because it's not otherwise possible to remove a single file from cache. If you explain your "Clear cache of an URL" use case we may be able to give a better suggestion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With