com.github.ignition.support.cache
Class ModelCache

java.lang.Object
  extended by com.github.ignition.support.cache.AbstractCache<String,CachedModel>
      extended by com.github.ignition.support.cache.ModelCache
All Implemented Interfaces:
Map<String,CachedModel>

public class ModelCache
extends AbstractCache<String,CachedModel>

Allows caching Model objects using the features provided by AbstractCache. The key into the cache will be based around the cached object's key, and the object will be able to save and reload itself from the cache.

Author:
Michael England

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
ModelCache(int initialCapacity, long expirationInMinutes, int maxConcurrentThreads)
          Creates an AbstractCache with params provided and name 'ModelCache'.
 
Method Summary
 String getFileNameForKey(String url)
          Only meaningful if disk caching is enabled.
 CachedModel put(String key, CachedModel value)
          Writes an element to the cache.
protected  CachedModel readValueFromDisk(File file)
          Only meaningful if disk caching is enabled.
 void removeAllWithPrefix(String prefix)
          Removes all cached objects with key prefix.
protected  void writeValueToDisk(File file, CachedModel data)
          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, 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

ModelCache

public ModelCache(int initialCapacity,
                  long expirationInMinutes,
                  int maxConcurrentThreads)
Creates an AbstractCache with params provided and name 'ModelCache'.

See Also:
com.github.droidfu.cachefu.AbstractCache#AbstractCache(java.lang.String, int, long, int)
Method Detail

put

public CachedModel put(String key,
                       CachedModel value)
Description copied from class: AbstractCache
Writes an element to the cache. NOTE: If disk caching is enabled, this will write through to the disk, which may introduce a performance penalty.

Specified by:
put in interface Map<String,CachedModel>
Overrides:
put in class AbstractCache<String,CachedModel>
See Also:
com.github.droidfu.cachefu.AbstractCache#put(java.lang.Object, java.lang.Object)

removeAllWithPrefix

public void removeAllWithPrefix(String prefix)
Removes all cached objects with key prefix.

Parameters:
prefix - Prefix of all cached object keys to be removed

getFileNameForKey

public String getFileNameForKey(String url)
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,CachedModel>
Parameters:
url - the cache key
Returns:
the file name
See Also:
com.github.droidfu.cachefu.AbstractCache#getFileNameForKey(java.lang.Object)

readValueFromDisk

protected CachedModel 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,CachedModel>
Parameters:
file - the file holding the cached value
Returns:
the cached value
Throws:
IOException
See Also:
com.github.droidfu.cachefu.AbstractCache#readValueFromDisk(java.io.File)

writeValueToDisk

protected void writeValueToDisk(File file,
                                CachedModel data)
                         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,CachedModel>
data - the cache value to persist
Throws:
IOException
See Also:
com.github.droidfu.cachefu.AbstractCache#writeValueToDisk(java.io.File, java.lang.Object)


Copyright © 2012. All Rights Reserved.