-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Clear cache ? #24
Comments
Do you mean the size on the sd card of the disk cache grows past 50mb? Or the size of the memory cache grows past 50mb? The limit you set for the disk cache is not necessarily a hard limit, according to the docs for the disk cache (https://github.com/JakeWharton/DiskLruCache), it may go over that limit by a small amount occasionally. If the disk cache is getting significantly larger than that limit, that's probably a bug and I can look in to it. |
The size grew up to 64MB last time I checked. And the cache always stayed in 60+MB on extensive usage of the app. We could clear the cache in onTrimMemory(). I wrote code to clear the directory but it crashes as the DiskLruCache holds references to the disk for images. Also skip cache would be possible if we are just able to find the reference to the disk image and delete them. Guess it's a good idea to give apes to clear the disk cache. Please find my implementation for clearing cache onTrimMemory ().
|
+1 |
Sorry I'm still a little unclear on what you're looking for. Do you want to be able to clear out the memory cache onLowMemory? Or the disk cache when the sd card is getting full? Or both? If you'd simply like the disk cache to use less space you can always set a lower limit. As long as it only exceeds the limit by a certain amount. I know that's not ideal, but it's also non trivial to write a disk cache. |
For me, the memory cache but a disc cache clean can also be go as a maintenance task. |
I'm a little hesitant to add this for either the memory or the disk cache, but I could be talked in to it. For the memory cache: You should be able to choose a safe memory cache size either for all devices or per device (as we do by default: https://github.com/bumptech/glide/blob/master/library/src/com/bumptech/glide/resize/ImageManager.java#L96) and never need to clear the cache. If there are memory leaks in either Glide or in applications using Glide, those should be fixed separately. For the disk cache: Assuming the size is bounded, even if the actual size on the sd card is somewhat larger than the max size you set, you can always decrease the max size until the actual size matches your target size. Clearing the catch will cause some large performance problems and also doesn't really solve the problem since the cache will just increase in size again until you happen to clear it. |
What we did (since we need to clear the cache too), is to create our own LruMemoryCache (based on the one from Glide) and expose two methods to clear and trim the cache. We then made Glide use our own instance which we expose to other parts of the app which handle the trimming and clearing |
Nice. Also a good alternative. |
Savvas if you want to throw up a pull request with that cache, I'd be happy to take a look and try to expose those methods through Glide (clearMemoryCache and clearDiskCache ?). I'll bow to the majority opinion here if you all would find it useful. |
Will do as soon as I make some needed changes in our fork. |
I submitted pull request: One note: I am not sure if I should be notifying the listener of removed bitmaps when clearing the cache completely. Any thoughts? |
@csobrinho I'd also be curious to see what you did with Volley to expire the cache. If Volley is only used for Glide, it might almost make sense to disable Volley's disk cache entirely since we do a better job of caching the minimal amount of data in Glide in most circumstances. |
GC goes haywire trying to clear and maintain 60% free space alltime after the pull. |
Are you calling the methods on the cache yourself? By default Glide doesn't actually call either clearMemory or trimMemory. If you have and are seeing issues I'll look in to it. |
yes without calling the clearMemory/trimMemory the GC goes wild, i suppose there are some memory leaks. |
Add clearMemory method here: 6244968 |
The application cache keeps growing past the 50mb mark for diskcache, should we write a logic ourselfs to clear the cache in the onTrimMemory() ?
The text was updated successfully, but these errors were encountered: