com.github.ignition.support.cache
Class ImageCache

java.lang.Object
  extended by com.github.ignition.support.cache.AbstractCache<String,byte[]>
      extended by com.github.ignition.support.cache.ImageCache
All Implemented Interfaces:
Map<String,byte[]>

public class ImageCache
extends AbstractCache<String,byte[]>

Implements a cache capable of caching image files. It exposes helper methods to immediately access binary image data as Bitmap objects.

Author:
Matthias Kaeppler

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class com.github.ignition.support.cache.AbstractCache
DISK_CACHE_INTERNAL, DISK_CACHE_SDCARD, diskCacheDirectory
 
Constructor Summary
ImageCache(int initialCapacity, long expirationInMinutes, int maxConcurrentThreads)
           
 
Method Summary
 android.graphics.Bitmap getBitmap(Object elementKey)
           
 String getFileNameForKey(String imageUrl)
          Only meaningful if disk caching is enabled.
protected  byte[] readValueFromDisk(File file)
          Only meaningful if disk caching is enabled.
 void removeAllWithPrefix(String urlPrefix)
           
protected  void writeValueToDisk(File file, byte[] imageData)
          Only meaningful if disk caching is enabled.
 
Methods inherited from class com.github.ignition.support.cache.AbstractCache
clear, clear, containsKey, containsKeyInMemory, containsKeyOnDisk, containsValue, enableDiskCache, entrySet, get, getCachedFiles, getDiskCacheDirectory, isDiskCacheEnabled, isEmpty, keySet, put, putAll, remove, removeKey, setDiskCacheEnabled, size, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

ImageCache

public ImageCache(int initialCapacity,
                  long expirationInMinutes,
                  int maxConcurrentThreads)
Method Detail

removeAllWithPrefix

public void removeAllWithPrefix(String urlPrefix)

getFileNameForKey

public String getFileNameForKey(String imageUrl)
Description copied from class: AbstractCache
Only meaningful if disk caching is enabled. See AbstractCache.enableDiskCache(android.content.Context, int). Turns a cache key into the file name that will be used to persist the value to disk. Subclasses must implement this.

Specified by:
getFileNameForKey in class AbstractCache<String,byte[]>
Parameters:
imageUrl - the cache key
Returns:
the file name

readValueFromDisk

protected byte[] readValueFromDisk(File file)
                            throws IOException
Description copied from class: AbstractCache
Only meaningful if disk caching is enabled. See AbstractCache.enableDiskCache(android.content.Context, int). Restores a value previously persisted to the disk cache.

Specified by:
readValueFromDisk in class AbstractCache<String,byte[]>
Parameters:
file - the file holding the cached value
Returns:
the cached value
Throws:
IOException

getBitmap

public android.graphics.Bitmap getBitmap(Object elementKey)

writeValueToDisk

protected void writeValueToDisk(File file,
                                byte[] imageData)
                         throws IOException
Description copied from class: AbstractCache
Only meaningful if disk caching is enabled. See AbstractCache.enableDiskCache(android.content.Context, int). Persists a value to the disk cache.

Specified by:
writeValueToDisk in class AbstractCache<String,byte[]>
imageData - the cache value to persist
Throws:
IOException


Copyright © 2012. All Rights Reserved.