简体   繁体   中英

DiskLRUCache for Bitmaps (and others) in Android

In android many image loading libraries (like Picasso -- which uses 2% of the storage for disk cache, Glide) use disk cache in addition to in memory lru cache. I can understand why this might be useful for images downloaded from the network -- if the in memory cache is full, read it from disk rather than fetching them remotely -- thus avoiding network latency etc. However, if we are just reading local images on the android device itself -- do we gain anything by using a separate disk cache with the serialized bitmap data -- since the data will have to be read from the disk anyways ? Probably makes sense if your app needs a thumbnail and subsample the original image once and store it in cache ? Are there any studies showing perf gains. I have seen use of disk cache in googles samples and other bitmap cache libraries.

so here are some refs I found in the AOSP docs :

A memory cache is useful in speeding up access to recently viewed bitmaps, however you cannot rely on images being available in this cache. Components like GridView with larger datasets can easily fill up a memory cache. Your application could be interrupted by another task like a phone call, and while in the background it might be killed and the memory cache destroyed. Once the user resumes, your application has to process each image again.

A disk cache can be used in these cases to persist processed bitmaps and help decrease loading times where images are no longer available in a memory cache. Of course, fetching images from disk is slower than loading from memory and should be done in a background thread, as disk read times can be unpredictable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM