3
votes

I'm implemented Glide library to load image in ImageView it's working fine.

Dependency:

compile "com.github.bumptech.glide:glide:4.5.0"
annotationProcessor "com.github.bumptech.glide:compiler:4.5.0"
compile "jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0"

In Adapter:

                    Glide.with(context)
                    .load(ImageUrl)
                    .apply(bitmapTransform(new jp.wasabeef.glide.transformations.BlurTransformation(25)
                    ).diskCacheStrategy(DiskCacheStrategy.ALL))
                    .apply(new RequestOptions()
                            .placeholder(R.mipmap.ic_launcher))
                    .into(view);

Issue is that when I'm upload image and display in recyclerview and get URL from API then it's display previously added image from cache instead of new one. I just need to add new image in first position instead of refresh whole list.

By using this:

.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)

Above code refresh whole list because clear whole cache data. I just need to display new uploaded image in list.

2
How load to image by add url or only your registered bitmap? And please share your adapterpropoLis
I do not think that you can check for particular url weather the content have been changed or not . So the solution can be use the unique url each time you upload image .ADM
Another solution is to user meta data of image resource. You have to utilize .signature() function of Glide. this might help. Simple solution is as mentioned by @ADM, Generate new url each time when the image gets uploaded.Paresh P.

2 Answers

0
votes

Please set like this:-

Glide.with(context)
        .load(img_url)
        .apply(new RequestOptions()
        .placeholder(R.mipmap.personal_pic)
        .diskCacheStrategy(DiskCacheStrategy.ALL))
        .into(iv_profile_pic);
1
votes

The first thing you need to verify are the response headers of your server/cdn or whatever you are using that hosts your images.

The only way for Glide to know if your image (from the same url) is updated is via cache/ETAG headers.

Now the tricky part: Glide is an image caching/loading library and it handles memory/disc caching but doesnt perform the actual networking part. It is handled by third party libraries such as OkHttp, so you will need to extend the glide modules and/or configure the network library to respect the cache headers in manner thats appropriate for your app.

Here are links to issues on glide github that will point you in the right direction:

https://github.com/bumptech/glide/issues/1257

https://github.com/bumptech/glide/issues/1847

https://github.com/bumptech/glide/issues/463