Glide: diskCacheStrategyOf(DiskCacheStrategy.NONE) not working in Glide 4.2.0

Created on 12 Oct 2017  路  9Comments  路  Source: bumptech/glide

I think I found a bug about cache setting.
Setting for "disable to use disk cache" (set to DiskCacheStrategy.NONE) is not working in Glide 4.2.0.

my code:

        Glide.with(getContext())
                .load(uri) // this uri is always same. because using one cache file
                .apply(RequestOptions.circleCropTransform())
                .apply(RequestOptions.skipMemoryCacheOf(true)) //
                .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.NONE))
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(mMainPicImgView);

It works in Glide 4.0.0-RC1.
but, It doesn't work in Glide 4.2.0.
Is there something wrong with my code? or this is a bug of the Glide 4.2?


Glide Version: classpath 'com.android.tools.build:gradle:2.3.3'


Integration libraries:
compile 'com.squareup.okhttp3:okhttp:3.8.1'


Device/Android Version:
Sony F3213 (Xperia XA Ultra), Android 7.0
Sony SO-01J (Xperia XZ), Android 7.0

question stale

Most helpful comment

@sjudd
Sorry for my question is not clear and my poor Eng. I'm not English speaker.
What I said "not working" means this.
Glide 4.2 does not refresh/invalidate the ImageView when you try to load the same url, even if RequestOptions have diskCacheStrategy(DiskCacheStrategy.NONE) setting.

I have exactly same situation with @Zoarg . I discovered this phenomenon when I tried to make a image crop function, too.

    @Override
    public void onCropComplete(@NonNull Uri uri) {
        // uri -> e.g.: getContext().getCacheDir() + "/cacheCroppedImg.jpg" (always same)

        RequestOptions requestOptions = new RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.NONE) // because file name is always same
                .skipMemoryCache(true)
                .circleCrop();

        Glide.with(getContext())
                .load(uri)
                .apply(requestOptions)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(mMainPicImgView);
// Glide should refresh the ImageView and show the new cropped image file. 
// However It is not working with Glide 4.2.0. 
// but, Glide 4.0.0 refresh the imageView correctrly, in this exactly same code. 
// I think the behavior of Glide 4.0.0 is correct.
    }

@Zoarg
So, I added this code, temporarily. before setting the newly cropped image into a ImageView.

// setting null first
        Glide.with(getContext())
                .load(null)
                .into(mMainPicImgView);

//after, setting the real uri
        Glide.with(getContext())
                .load(uri)
                .apply(requestOptions)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(mMainPicImgView);

All 9 comments

Can you clarify what you mean by not working?

I have same issues. In 4.0.0 version RequestOptions.diskCacheStrategyOf(DiskCacheStategy.NONE) is working fine.

Example:
Activity A shows image in imageView, onClick on imageView starts Activity B where cropping image is done. After cropping is done, Activity B is finished and Activity A is resumed. In version 4.0.0, Glide would load cropped image (not from cache) in Activity A, but in newer version of Glide that is not the case (it shows original image instead of cropped one).

Maybe I have missed something that I don't know.

@sjudd
Sorry for my question is not clear and my poor Eng. I'm not English speaker.
What I said "not working" means this.
Glide 4.2 does not refresh/invalidate the ImageView when you try to load the same url, even if RequestOptions have diskCacheStrategy(DiskCacheStrategy.NONE) setting.

I have exactly same situation with @Zoarg . I discovered this phenomenon when I tried to make a image crop function, too.

    @Override
    public void onCropComplete(@NonNull Uri uri) {
        // uri -> e.g.: getContext().getCacheDir() + "/cacheCroppedImg.jpg" (always same)

        RequestOptions requestOptions = new RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.NONE) // because file name is always same
                .skipMemoryCache(true)
                .circleCrop();

        Glide.with(getContext())
                .load(uri)
                .apply(requestOptions)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(mMainPicImgView);
// Glide should refresh the ImageView and show the new cropped image file. 
// However It is not working with Glide 4.2.0. 
// but, Glide 4.0.0 refresh the imageView correctrly, in this exactly same code. 
// I think the behavior of Glide 4.0.0 is correct.
    }

@Zoarg
So, I added this code, temporarily. before setting the newly cropped image into a ImageView.

// setting null first
        Glide.with(getContext())
                .load(null)
                .into(mMainPicImgView);

//after, setting the real uri
        Glide.with(getContext())
                .load(uri)
                .apply(requestOptions)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(mMainPicImgView);

Using just DiskCacheStrategy.NONE and skipMemoryCache isn't sufficient to guarantee that you will load a new image every time. Instead, you should be using the signature API.

As an added bonus if your file path is constant for some period of time, you can use both the disk cache and memory cache and only change your signature when you know the contents of the file have changed.

That said, you were probably affected by some of the changes related to #2270 in 4.2 which makes using DiskCacheStrategy.NONE and skipMemoryCache less likely to work.

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

Same problem with Glide 4.2.0. When i crop image and try to load ,it display old cached image. Any solution?

As @sjudd said you can use signature to achieve that. Below is a sample code in Kotlin.

Glide.with(this)
          .load(imageUri)
          .transition(DrawableTransitionOptions.withCrossFade())
          .apply(RequestOptions.circleCropTransform()
          .signature(ObjectKey(DateTime.now().millis)))
          .into(placeholder_image)

As @sjudd said you can use signature to achieve that. Below is a sample code in Kotlin.

Glide.with(this)
          .load(imageUri)
          .transition(DrawableTransitionOptions.withCrossFade())
          .apply(RequestOptions.circleCropTransform()
          .signature(ObjectKey(DateTime.now().millis)))
          .into(placeholder_image)

I have tried that but it does not work: https://stackoverflow.com/questions/53122386/glide-enlarges-user-image-after-i-close-and-reopen-the-app

@rajdeepsh I don't think your issue is related to caching, see http://bumptech.github.io/glide/doc/targets.html#sizes-and-dimensions. if you still have questions please file a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sergeyfitis picture sergeyfitis  路  3Comments

kooeasy picture kooeasy  路  3Comments

piedpiperlol picture piedpiperlol  路  3Comments

Anton111111 picture Anton111111  路  3Comments

sant527 picture sant527  路  3Comments