开发者

EhCache in Android for caching bitmap images?

开发者 https://www.devze.com 2023-02-10 05:15 出处:网络
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 differen

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'开发者_Python百科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

0

精彩评论

暂无评论...
验证码 换一张
取 消