I want to use the DiskLruCache
from Jake Wharton in my Android app based on API Level 7+. I would use it in my ListView to Cache downloaded images on SdCard but i didn't understood the usage of this library.
Can anybody show me a example of how to get Bitmaps from this Cache or put Bitmaps in the cache? ( key = filePath, value = Bitmap )
I found no method to get the Value of this Snapshot Object.
Thanks for every help.
The DiskLruCache opens a stream to a particular location in the directory. For example, for getting a stream at index 0( remember we can save multiple values for a particular key), and converting it to BufferedStream for writing data, we use. OutputStream out = new BufferedOutputStream(editor.
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.
LruCache . Used to write apps that run on API levels prior to 12. When running on API level 12 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.
I used getBitmap() in the sample someone posted here.
This is the answer you're looking for under a different title. You will have to create a Utils for some of the code but it's pretty straightforward.
Good Luck!
Using DiskLruCache in android 4.0 does not provide for openCache method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With