Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload image in Glide from the same url?

I am using Glide image loader to load an image from a specific URL, now if I update the image to the same URL, Glide is still showing the cached image in my imageview. How to reload the image from the same URL?

like image 519
Ajay Chauhan Avatar asked Dec 19 '17 11:12

Ajay Chauhan


3 Answers

As per the Glide wiki Caching-and-Cache-Invalidation

Option 1 (Glide v4): Use ObjectKey to change the file's date modified time.

Glide.with(requireContext())
    .load(myUrl)
    .signature(ObjectKey(System.currentTimeMillis().toString()))
    .into(myImageView)

Option 1 (Glide v3): Use StringSignature to change the file's date modified time.

URLs - Although the best way to invalidate URLs is to make sure the server changes the URL and updates the client when the content at the URL changes, you can also use StringSignature to mix in arbitrary metadata

Glide.with(yourFragment)
    .load(url)
    .signature(new StringSignature(String.valueOf(System.currentTimeMillis()))
    .into(yourImageView);

If all else fails and you can neither change your identifier nor keep track of any reasonable version metadata,

Option 2: You can also disable disk caching entirely using diskCacheStrategy() and DiskCacheStrategy.NONE

Glide.with(Activity.this).load(url)
    .diskCacheStrategy(DiskCacheStrategy.NONE )
    .skipMemoryCache(true)
    .into(imageView);

Reference: https://github.com/bumptech/glide/wiki/Caching-and-Cache-Invalidation

like image 121
Ramesh sambu Avatar answered Oct 18 '22 22:10

Ramesh sambu


Add

signature(new ObjectKey(String.valueOf(System.currentTimeMillis())))

RequestOptions requestOptions = new RequestOptions();
            requestOptions.placeholder(R.drawable.cover_placeholder);
            requestOptions.error(R.drawable.no_image_available);
            requestOptions.signature(
                      new ObjectKey(String.valueOf(System.currentTimeMillis())));


Glide.with(MosaicFragment.this)
                 .setDefaultRequestOptions(requestOptions)
                 .load(finalPathOrUrl)
like image 5
Alex Avatar answered Oct 18 '22 20:10

Alex


Use .diskCacheStrategy(DiskCacheStrategy.NONE)

Glide.with(context)
     .load(url)
     .apply(new RequestOptions()
             .placeholder(R.drawable.placeholder)
             .error(R.drawable.error)
             .diskCacheStrategy(DiskCacheStrategy.NONE)
             .skipMemoryCache(true))
     .into(ImageView);
like image 4
Goku Avatar answered Oct 18 '22 21:10

Goku