octo-online/robospice — pull request #41 by weefbellington (2013-02-08 18:28:58+00:00)
Title: LRU cache object persister classes

[LruCache_url]:http://developer.android.com/reference/android/support/v4/util/LruCache.html

I've created a fork of Robospice that adds a few types of object persisters, based on the [LruCache][LruCache_url] class from the Android support library. There are two concrete classes to support bitmap caching and one abstract class that can be extended to create any kind of LRU cache object persister.

## Classes

### InMemoryLRUCacheObjectPersister

An abstract, generic `ObjectPersister` class. Handles saving/loading of items to an `LruCache`. When the size of the cache grows too large, it will evict the least recently used objects. Subclasses must implement the `instantiateLRUCache()` method. The constructor has an optional fallback parameter, allowing it to specify an alternate cache to draw from in case the data does not exist or has been evicted. This permits a two-level caching scheme, with the volatile in-memory cache being backed by a stable file cache.

### InMemoryBitmapObjectPersister

A concrete implementation of the `InMemoryLRUCacheObjectPersister` for `Bitmap` objects. By default, it allows the cache to grow to 1/4 of the available memory size, but the size is configurable.

### InFileBitmapObjectPersister

A file persister for bitmap objects. Handles compression to disk and decoding into memory. Intended to be a fallback for the `InMemoryBitmapObjectPersister` but can be used independently.

## Tests

The fork contains unit tests for all the classes. A demo for the robospice-samples project is upcoming.