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
Disk cache not working everytime the app is restarted #4429
Comments
You can store image to cache once its loaded. |
Hey, thanks for your answer. Using Android Studio's Device File Explorer, I was able to see that the default cache directory ( /data/user/0/<my_app>/cache/image_manager_disk_cache ) worked and was filled with the proper cache keys. When the app is killed, the directory is still ok. But as soon as I restart the app and Glide is reinitialized, I can see this directory is flushed. It looks like Glide flushes this directory everytime it starts, but I haven't pinpointed what part of the code is responsible for this yet. |
Glide doesn't do anything to clear out the disk cache automatically. But there is a clearDiskCache method:
Maybe put a break point there and see what happens? It's also possible something else in the app or in a library you use is going through and deleting things out of the cache. The system also has the ability to do it as well, either automatically or via clear cache in the application options. |
try out this for cache |
Thanks for the hint, I've found the culprit. As a matter of fact, I was using Exoplayer at the same time with
Adding a subfolder to this cache like so: The issue is solved, thanks. |
Glide Version:
4.12.0-SNAPSHOT
4.11.0
4.8.0
Integration libraries: None
Device/Android Version:
OnePlus 6, Android 10 (OxygenOS 10.3.7)
Emulator, API 27
Issue details / Repro steps / Use case background:
Note: if I just navigate through the app and go back to the image, I get successful cache hits from either MEMORY_CACHE or DATA_DISK_CACHE (which guarantees me the cache exists and works). The issue only occurs when restarting the app.
One of the most notable consequences of this is I cannot use Glide to make an offline mode if the user temporarily loses its connection. Also it makes Glide use more bandwidth than it should if I believe the docs : https://bumptech.github.io/glide/doc/caching.html
Glide load line /
GlideModule
(if any) / list Adapter code (if any):No GlideModule (although I still have the problem if I add one).
Layout XML:
Stack trace / LogCat: No error message.
After restarting the app, I get the exact same log line (still REMOTE, same URL, same target size, same call).
Am I missing something here, or is this the expected behavior? After the app is killed, it looks like the whole cache is flushed: if I add
onlyRetrieveFromCache(true)
to the above call just before restarting, Glide cannot find the image (I get an exception in the logs). Or maybe there is a parameter to persist the disk cache?Thanks.
The text was updated successfully, but these errors were encountered: