Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of JakeWhartons DiskLruCache

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.

like image 628
Happo Avatar asked Aug 20 '12 12:08

Happo


People also ask

What is DiskLruCache?

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.

What is Image Manager disk cache?

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.

What is LRU cache in android?

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.


1 Answers

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

like image 143
John Stack Avatar answered Nov 29 '22 18:11

John Stack