10

Looking for a simple open source non-copyleft caching for Android (SDK 7+) class.

The purpose is primary to store the Bitmaps fetched asynchronously (so i don't need this functionality to be included in the cache class).

I was using a weakList for this purpose, that was naturally a bad solution, with Guava cache that is a little better but still not fine.

It's preferred that the cache is able to store any serializable Object, not just a Bitmap, and that i could easily purge the objects of certain tag used while the object is added to cache.

The best option would be to get the filesystem cache like wrapping the sqlite database. It would be great if the cache would be cleared by Settings >Manage Application > Clear Cache

A-Live
  • 8,904
  • 2
  • 39
  • 74

7 Answers7

9

The plain LruCache suggested above is an in memory cache. From your question it sounds like you are looking for a disk cache solution.

Read the Disk Cache of the Caching Bitmaps android training doc.

Then take a look at the DiskLruCache implementation discussed on the following thread : Using DiskLruCache in android 4.0 does not provide for openCache method

You can grab the DiskLruCache source on GitHub.

Community
  • 1
  • 1
Akos Cz
  • 12,711
  • 1
  • 37
  • 32
4

How about android.util.LruCache? If you need to support older platforms, simply copy it in you project. EDIT: it's actually in the compat/support library.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • Guava cache seems to be more flexible, and i'd prefer now to use not runtime but filesystem cache, thanks for the hint though. – A-Live Jul 18 '12 at 03:37
  • http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html An article on android discussing options for image caching. – krishnakumarp Jul 18 '12 at 05:54
3

ICSDiskLruCache.java. This is a port of the DiskLruCache available in ICS and later versions of Android, open-sourced by Google as part of the IO 2012 Android App so it works with versions down to (at least) API level 7.

Find the source at http://code.google.com/p/iosched/source/browse/android/src/com/google/android/apps/iosched/util/ICSDiskLruCache.java

Nik
  • 2,380
  • 2
  • 16
  • 15
  • The file can be found at: https://github.com/google/iosched/blob/f4fd7504d43b25a75cc23b58d6f844f3553b48c3/android/src/com/google/android/apps/iosched/util/ICSDiskLruCache.java – Hassan Ibraheem May 18 '14 at 08:14
2

Ignition is what are you looking for: https://github.com/kaeppler/ignition. It allows you to cache images, serialized objects. For cashing part, work with ignition-support

Here's the API for ignition support: http://kaeppler.github.com/ignition-docs/ignition-support/apidocs/.

Andy Res
  • 15,963
  • 5
  • 60
  • 96
1

I would recommend that you use the wide-used and before known as droid-fu the refactored and really powerful lib called ignition. The ignition library is mainly maintain by Matthias Käppler lead mobile dev of Qype. The library has a cache framework and RemoteImage Widget (and many more useful classes). Moreover is Maven ready, so is easy to add the dependency. Take a look at the cache javadoc: http://kaeppler.github.com/ignition-docs/ignition-support/apidocs/

rallat
  • 1,275
  • 1
  • 10
  • 16
1

You can create your own image cache following this official android documentation that not only gives you the code, but also explains how it works:

http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html

They also explain the whole process, from loading bitmaps, processing them in a background thread, caching them and displaying them

http://developer.android.com/training/displaying-bitmaps/index.html

Fernando Gallego
  • 4,064
  • 31
  • 50