com.github.ignition.support.http.cache
Class HttpResponseCache

java.lang.Object
  extended by com.github.ignition.support.cache.AbstractCache<String,CachedHttpResponse.ResponseData>
      extended by com.github.ignition.support.http.cache.HttpResponseCache
All Implemented Interfaces:
Map<String,CachedHttpResponse.ResponseData>

public class HttpResponseCache
extends AbstractCache<String,CachedHttpResponse.ResponseData>

Allows caching HTTP responses (only status code and payload at the moment) using the features provided by AbstractCache. The key into the cache will be the request URL used to retrieve the HTTP response in the first place.

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
HttpResponseCache(int initialCapacity, long expirationInMinutes, int maxConcurrentThreads)
           
 
Method Summary
 String getFileNameForKey(String url)
          Only meaningful if disk caching is enabled.
protected  CachedHttpResponse.ResponseData readValueFromDisk(File file)
          Only meaningful if disk caching is enabled.
 void removeAllWithPrefix(String urlPrefix)
           
protected  void writeValueToDisk(File file, CachedHttpResponse.ResponseData 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, 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

HttpResponseCache

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

removeAllWithPrefix

public void removeAllWithPrefix(String urlPrefix)

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,CachedHttpResponse.ResponseData>
Parameters:
url - the cache key
Returns:
the file name

readValueFromDisk

protected CachedHttpResponse.ResponseData 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,CachedHttpResponse.ResponseData>
Parameters:
file - the file holding the cached value
Returns:
the cached value
Throws:
IOException

writeValueToDisk

protected void writeValueToDisk(File file,
                                CachedHttpResponse.ResponseData 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,CachedHttpResponse.ResponseData>
data - the cache value to persist
Throws:
IOException


Copyright © 2012. All Rights Reserved.