Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove glide cache - android?

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?

like image 622
TheQ Avatar asked Jun 24 '26 08:06

TheQ


2 Answers

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.

like image 138
Vinay John Avatar answered Jun 25 '26 23:06

Vinay John


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.

like image 38
Jigar Patel Avatar answered Jun 25 '26 23:06

Jigar Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!