Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove image from cache / clear cache issue #2795

Closed
BenjaminZaiser opened this issue Jan 9, 2018 · 5 comments
Closed

Remove image from cache / clear cache issue #2795

BenjaminZaiser opened this issue Jan 9, 2018 · 5 comments

Comments

@BenjaminZaiser
Copy link

Dear development team,

I'm using Glide to display product images in my app, e.g. on product detail page:

Glide.with( context )
         .load( url )
         .thumbnail( Glide.with( context )
            .load( placeholderResId )
            .apply( new RequestOptions()
               .centerCrop() ) )
         .into( productImageView );

The caching mechanism of this library is really great to reduce the used bandwidth of the user, but now I have some problem where I need your help:

Given product detail page is displayed along with a product image.
When user deletes product image
and reopens product detail page
Then product image should not be visible anymore (placeholder should be shown).

Problem:
Currently the product image will be loaded from the cache and is displayed to the user which is not expected.

I would like to have the feature to delete a single image in the cache. But I found out, this is not possible.
I found this #552 and decided to go with the 1st solution, although it has some disadvantages for the user (deletion of product images is very rare).

Calling Glide.get( getApplicationContext() ).clearDiskCache(); is not sufficient, because the image could still be in the memory. So I have to call Glide.get( getApplicationContext() ).clearMemory(); as well. But when I want to open the product detail page again, I get the following error message:

java.lang.IllegalStateException: cache is closed
                                        at com.bumptech.glide.disklrucache.DiskLruCache.checkNotClosed(DiskLruCache.java:620)
                                        at com.bumptech.glide.disklrucache.DiskLruCache.get(DiskLruCache.java:409)
                                        at com.bumptech.glide.load.engine.cache.DiskLruCacheWrapper.get(DiskLruCacheWrapper.java:75)
                                        at com.bumptech.glide.load.engine.ResourceCacheGenerator.startNext(ResourceCacheGenerator.java:62)
                                        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:298)
                                        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:265)
                                        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:229)
                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                        at java.lang.Thread.run(Thread.java:764)
                                        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:413)

What do I need to do to "reinitialize" Glide? Or do you have another approach to the problem?
Thanks
Ben

Glide Version: 4.3.1

Integration libraries: OkHttp3

Device/Android Version: Nexus 5X

Issue details / Repro steps / Use case background:

Glide load line / GlideModule (if any) / list Adapter code (if any):

Glide.with...

Layout XML:

<FrameLayout xmlns:android="...

Stack trace / LogCat:

paste stack trace and/or log here
@sjudd
Copy link
Collaborator

sjudd commented Jan 10, 2018

Maybe a duplicate of #2465, let me know if you're able to reproduce in 4.4.0 or higher.

@sjudd
Copy link
Collaborator

sjudd commented Jan 10, 2018

Also you're probably better off using a signature unless you need the actual bytes deleted off of disk. See http://bumptech.github.io/glide/doc/caching.html#cache-invalidation

@sjudd sjudd added the question label Jan 10, 2018
@stale
Copy link

stale bot commented Jan 17, 2018

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.

@stale stale bot added the stale label Jan 17, 2018
@BenjaminZaiser
Copy link
Author

I can confirm that this issue is fixed in 4.5.0 version.
Thanks :-)

@sjudd
Copy link
Collaborator

sjudd commented Jan 23, 2018

Thanks for following up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants