public class PreloadDataCache<K,V> extends SimpleCache<K,V>
setOnGetDataListener(OnGetDataListener) set how to get data, this cache will get data and preload data
 by itSimpleCache.setCacheFullRemoveType(CacheFullRemoveType) set remove type when cache is fullget(Object, List) get object, if list is not null, will preload data auto according to keys in listget(Object) get object, and not preload datasetForwardCacheNumber(int) set count for preload forward, default is
 DEFAULT_FORWARD_CACHE_NUMBERsetBackwardCacheNumber(int) set count for preload backward, default is
 DEFAULT_BACKWARD_CACHE_NUMBERsetContext(Context) and setAllowedNetworkTypes(int) restrict the types of networks over which
 this data can get.SimpleCache.setValidTime(long) set valid time of elements in cache, in millsSimpleCache.saveCache(String, SimpleCache) save cache to a filePreloadDataCache()PreloadDataCache(int)PreloadDataCache(int, int)loadCache(String) restore cache from file| Modifier and Type | Class and Description | 
|---|---|
| static interface  | PreloadDataCache.OnGetDataListener<K,V>get data interface, implements this to get data | 
| Modifier and Type | Field and Description | 
|---|---|
| static int | DEFAULT_BACKWARD_CACHE_NUMBERdefault count for preload backward | 
| static int | DEFAULT_FORWARD_CACHE_NUMBERdefault count for preload forward | 
| static int | DEFAULT_THREAD_POOL_SIZEdefault getting data thread pool size | 
| static int | NETWORK_MOBILEBit flag for  setAllowedNetworkTypes(int)corresponding toConnectivityManager#TYPE_MOBILE. | 
| static int | NETWORK_WIFIBit flag for  setAllowedNetworkTypes(int)corresponding toConnectivityManager#TYPE_WIFI. | 
DEFAULT_MAX_SIZE| Constructor and Description | 
|---|
| PreloadDataCache()
 Maximum size of the cache is  SimpleCache.DEFAULT_MAX_SIZEElements of the cache will not invalid, can set bySimpleCache.setValidTime(long)Remove type isRemoveTypeEnterTimeFirstwhen cache is full
 Size of getting data thread pool isDEFAULT_THREAD_POOL_SIZE | 
| PreloadDataCache(int maxSize)
 Elements of the cache will not invalid, can set by  SimpleCache.setValidTime(long)Remove type isRemoveTypeEnterTimeFirstwhen cache is full
 Size of getting data thread pool isDEFAULT_THREAD_POOL_SIZE | 
| PreloadDataCache(int maxSize,
                int threadPoolSize)
 Elements of the cache will not invalid, can set by  SimpleCache.setValidTime(long)Remove type isRemoveTypeEnterTimeFirstwhen cache is full | 
| Modifier and Type | Method and Description | 
|---|---|
| boolean | checkIsNetworkTypeAllowed()Check if get data can proceed over the given network type. | 
| CacheObject<V> | get(K key)get data synchronous
 
 if key is null, return null, else
 if key is already in cache, return the element that mapping with the specified key, else
 call  PreloadDataCache.OnGetDataListener.onGetData(Object)to get data and wait for it finish | 
| CacheObject<V> | get(K key,
   java.util.List<K> keyList)get data synchronous and preload new data asynchronous according to keyList | 
| int | getAllowedNetworkTypes()get the types of networks over which this data can get | 
| int | getBackwardCacheNumber()get count for preload backward, default is  DEFAULT_BACKWARD_CACHE_NUMBER | 
| Context | getContext() | 
| int | getForwardCacheNumber()get count for preload forward, default is  DEFAULT_FORWARD_CACHE_NUMBER | 
| PreloadDataCache.OnGetDataListener<K,V> | getOnGetDataListener()get get data listener | 
| boolean | isCheckNetwork()get whether to check the network at first when get data, used when  checkIsNetworkTypeAllowed() | 
| boolean | isExistGettingDataThread(K key)whether there is a thread which is getting data for the specified key | 
| static <K,V> PreloadDataCache<K,V> | loadCache(java.lang.String filePath)restore cache from file | 
| void | setAllowedNetworkTypes(int allowedNetworkTypes)Restrict the types of networks over which this data can get. | 
| void | setBackwardCacheNumber(int backwardCacheNumber)set count for preload backward, default is  DEFAULT_BACKWARD_CACHE_NUMBER | 
| void | setCheckNetwork(boolean isCheckNetwork)set whether to check the network at first when get data, used when  checkIsNetworkTypeAllowed() | 
| void | setContext(Context context)used when  checkIsNetworkTypeAllowed() | 
| void | setForwardCacheNumber(int forwardCacheNumber)set count for preload forward, default is  DEFAULT_FORWARD_CACHE_NUMBER | 
| void | setOnGetDataListener(PreloadDataCache.OnGetDataListener<K,V> onGetDataListener)set get data listener, this cache will get data and preload data by it | 
| java.util.List<java.lang.Runnable> | shutdownNow() | 
clear, containsKey, entrySet, getCacheFullRemoveType, getHitCount, getHitRate, getMaxSize, getMissCount, getSize, getValidTime, keySet, put, put, putAll, remove, saveCache, setCacheFullRemoveType, setValidTime, valuespublic static final int DEFAULT_FORWARD_CACHE_NUMBER
public static final int DEFAULT_BACKWARD_CACHE_NUMBER
public static final int DEFAULT_THREAD_POOL_SIZE
public static final int NETWORK_MOBILE
setAllowedNetworkTypes(int) corresponding to ConnectivityManager#TYPE_MOBILE.public static final int NETWORK_WIFI
setAllowedNetworkTypes(int) corresponding to ConnectivityManager#TYPE_WIFI.public PreloadDataCache()
SimpleCache.DEFAULT_MAX_SIZESimpleCache.setValidTime(long)RemoveTypeEnterTimeFirst when cache is fullDEFAULT_THREAD_POOL_SIZEpublic PreloadDataCache(int maxSize)
SimpleCache.setValidTime(long)RemoveTypeEnterTimeFirst when cache is fullDEFAULT_THREAD_POOL_SIZEmaxSize - maximum size of the cachepublic PreloadDataCache(int maxSize,
                int threadPoolSize)
SimpleCache.setValidTime(long)RemoveTypeEnterTimeFirst when cache is fullmaxSize - maximum size of the cachethreadPoolSize - getting data thread pool sizepublic CacheObject<V> get(K key, java.util.List<K> keyList)
key - keyList - key list, if is null, not preload, else preload forward by
 preloadDataForward(Object, List, int), preload backward by
 preloadDataBackward(Object, List, int)get(Object)public CacheObject<V> get(K key)
PreloadDataCache.OnGetDataListener.onGetData(Object) to get data and wait for it finishpublic boolean isExistGettingDataThread(K key)
key - public int getForwardCacheNumber()
DEFAULT_FORWARD_CACHE_NUMBERpublic void setForwardCacheNumber(int forwardCacheNumber)
DEFAULT_FORWARD_CACHE_NUMBERforwardCacheNumber - public int getBackwardCacheNumber()
DEFAULT_BACKWARD_CACHE_NUMBERpublic void setBackwardCacheNumber(int backwardCacheNumber)
DEFAULT_BACKWARD_CACHE_NUMBERbackwardCacheNumber - public PreloadDataCache.OnGetDataListener<K,V> getOnGetDataListener()
public void setOnGetDataListener(PreloadDataCache.OnGetDataListener<K,V> onGetDataListener)
onGetDataListener - public int getAllowedNetworkTypes()
public void setAllowedNetworkTypes(int allowedNetworkTypes)
getContext() is not nullallowedNetworkTypes - any combination of the NETWORK_* bit flags.public boolean isCheckNetwork()
checkIsNetworkTypeAllowed()public void setCheckNetwork(boolean isCheckNetwork)
checkIsNetworkTypeAllowed()isCheckNetwork - public Context getContext()
public void setContext(Context context)
checkIsNetworkTypeAllowed()context - public boolean checkIsNetworkTypeAllowed()
networkType - a constant from ConnectivityManager.TYPE_*.getContext() is null, return truegetAllowedNetworkTypes() is not match network, return falsepublic static <K,V> PreloadDataCache<K,V> loadCache(java.lang.String filePath)
filePath - public java.util.List<java.lang.Runnable> shutdownNow()
ExecutorService.shutdownNow()