Does glide not update android image of same url?

I have the same URL for the image. When I update this image more than once, it shows the previous image. The version of the image and image on the server is updated, but Glide does not show the new image. I want to get a new image every time and cache it.

Glide.with(context)
        .load(Constants.COPY_LINK_BASE_URL + info.getDisplayPicture())
        .placeholder(R.drawable.ic_profile).dontAnimate()
        .diskCacheStrategy(DiskCacheStrategy.SOURCE)
        .signature(new (SettingManager.getUserPictureVersion(context)))
        .into(ivUserProfilePhoto);

I can reproduce this error by changing the Internet, changing the image on one Internet, as expected on the other Internet, it will remain the same after 2 or 3 attempts to change the image

+23
source share
9 answers
//Use bellow code, it work for me.Set skip Memory Cache to true. it will load the image every time.

 Glide.with(Activity.this)
.load(theImagePath)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(myImageViewPhoto);
+23
source

Glide 4.x

Glide.with(context)
     .load(imageUrl)
     .apply(RequestOptions.skipMemoryCacheOf(true))
     .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
     .into(imageView);

Glide 3.x

Glide.with(context)
     .load(imageUrl)
     .skipMemoryCache(true)
     .diskCacheStrategy(DiskCacheStrategy.NONE)
     .into(imageView);
+19

, , . , (Picasso Glide) .

Glide API, : https://github.com/bumptech/glide/wiki/Caching-and-Cache-Invalidation

Glide.with(yourFragment)
    .load(yourFileDataModel)
    .signature(new StringSignature(yourVersionMetadata))
    .into(yourImageView);

, , API, , , .

, ETags.

!

+6

Glide .signature(), @MGDavies -

// in kotlin
Glide.with(context)
        .load("url")
        //using apply to RequestOptions instead signature directly
        .apply(RequestOptions().signature(ObjectKey("time that image was updated")))
        .into(thumb)
+6

, ( ). , Glide , .

, : , .

. , Glide . :

Glide.with(context)
         .load(Constants.COPY_LINK_BASE_URL + info.getDisplayPicture())
         .placeholder(R.drawable.ic_profile).dontAnimate()
         .diskCacheStrategy(DiskCacheStrategy.NONE)
         .skipMemoryCache(true)
         .signature(new (SettingManager.getUserPictureVersion(context)))
         .into(ivUserProfilePhoto);

. ( , )

Glide.with(context)
         .load(Constants.COPY_LINK_BASE_URL + info.getDisplayPicture())
         .placeholder(R.drawable.ic_profile).dontAnimate()
         .signature(new StringSignature(String.valueOf(System.currentTimeMillis())))
         .into(ivUserProfilePhoto);

- .diskCacheStrategy(DiskCacheStrategy.SOURCE).

Glide caching API .

+5

, , - :

| == | Clear Glide memory

 Glide.get(getApplicationContext()).clearMemory();

| == | Clear Glide Cache()

void clearGlideDiskCache()
{
    new Thread(new Runnable()
    {
        @Override
        public void run()
        {
            Glide.get(getApplicationContext()).clearDiskCache();
        }
    }).start();
}
+3

Glide , RequestOption .

RequestOptions options = new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true);

signature.

RequestOptions options = new RequestOptions()
.signature(new StringSignature(String.valueOf(System.currentTimeMillis())));

:

Glide.with(CompressSingleActivity.this)
.applyDefaultRequestOptions(options)
.load(currentFile)
.into(currentImageView);
+3

it’s like the problem is with the Glide library itself, I found a trick that can fix it, just put a random number after the URL of your image as a request, as an example code below, this solved my problem, I hope it helps you too

        Random random = new Random();
        int randomInt = random.nextInt();
        Glide.with(context)
                .applyDefaultRequestOptions(new RequestOptions()
                        .circleCrop().diskCacheStrategy(DiskCacheStrategy.NONE))
                .load(ConstantVars.BaseUrl + userModel.getAvatarURL() + "?" + randomInt)
                .apply(new RequestOptions().error(R.drawable.himart_place_holder))
                .into(imageViewProfile);

this will cause Glide to reload the image every time you request, as if there is no read cache.

0
source

Glide 4.8.0

    Glide.with(mContext)
            .asBitmap()
            .load(nopicUrl)
            .apply(RequestOptions.skipMemoryCacheOf(true))
            .apply(RequestOptions.signatureOf(new ObjectKey(String.valueOf(System.currentTimeMillis()))))
            .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.DATA))
            .into(ivImageView);
0
source

Source: https://habr.com/ru/post/1667328/


All Articles