简体   繁体   中英

EhCache in Android for caching bitmap images?

I'm writing a fairly Android application which will need to cache a lot of different images around 48x48 to 500x500 pixels in size. These images are fetched over the network from a number of different sources (think: user selects a source, browses a bunch of images, changes source, browses a bunch of images, etc.). I'd like to implement caching for these images, as I don't want to hit HTTP if someone's flinging through some images they've already seen. Obviously, memory usage is pretty key, so that's where EhCache comes in, as it offers a lot of different options for bounding the cache, expanding it to disk, etc.

Is this the right/best way to go about caching these images? I have noticed a lot of applications cache right to disk on the SD card, but I'd like to avoid this if possible for the sake of speed/convenience.

You should check out Matthias Kaeppler's project Droid-Fu:
https://github.com/mttkay/droid-fu

In Droid-Fu, there is an ImageCache , which uses memory for the first level cache, and disk for the second level. It it specifically made for Android, and does the right thing there, which is to use the designated cache directory for the current application instead of polluting the sdcard or other directories. Android can automatically clean up the cache directory when it needs to.

Here is the Javadoc:
http://mttkay.github.com/droid-fu/com/github/droidfu/imageloader/ImageCache.html

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