3

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?

OneCricketeer
  • 151,199
  • 17
  • 111
  • 216
TheQ
  • 1,869
  • 7
  • 36
  • 61

2 Answers2

6
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.

Vinay John
  • 931
  • 11
  • 13
1

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.

Jigar Patel
  • 1,500
  • 2
  • 12
  • 28