public class SimpleCache<K,V> extends java.lang.Object implements Cache<K,V>, java.io.Serializable
setCacheFullRemoveType(CacheFullRemoveType) set remove type when cache is fullsetValidTime(long) set valid time of elements in cache, in millsput(Object, CacheObject) or put(Object, Object) put elementget(Object) get elementloadCache(String) restore cache from filesaveCache(String, SimpleCache) save cache to fileSimpleCache()SimpleCache(int)loadCache(String) restore cache from filegetHitRate() get hit rate of the cachegetHitCount() get hit count of the cachegetMissCount() get miss count of the cachegetMaxSize() get the maximum capacity of the cachegetSize() get the number of elements in the cache validMap 
 | Modifier and Type | Field and Description | 
|---|---|
| static int | DEFAULT_MAX_SIZEdefault maximum capacity of the cache | 
| Constructor and Description | 
|---|
| SimpleCache()
 Maximum size of the cache is  DEFAULT_MAX_SIZEElements of the cache will not invalid, can set bysetValidTime(long)Remove type isRemoveTypeEnterTimeFirstwhen cache is full | 
| SimpleCache(int maxSize)
 Elements of the cache will not invalid, can set by  setValidTime(long)Remove type isRemoveTypeEnterTimeFirstwhen cache is full | 
| Modifier and Type | Method and Description | 
|---|---|
| void | clear()Removes all elements from this Map, leaving it empty. | 
| boolean | containsKey(K key)whether this cache contains the specified key. | 
| java.util.Set<java.util.Map.Entry<K,CacheObject<V>>> | entrySet()key value set | 
| CacheObject<V> | get(K key)get element | 
| CacheFullRemoveType<V> | getCacheFullRemoveType()get remove type when cache is full | 
| long | getHitCount()get hit count | 
| double | getHitRate()get hit rate | 
| int | getMaxSize()get the maximum capacity of the cache | 
| long | getMissCount()get miss count | 
| int | getSize()get the number of elements in the cache valid | 
| long | getValidTime()get valid time of elements in cache, in mills. | 
| java.util.Set<K> | keySet()key set | 
| static <K,V> SimpleCache<K,V> | loadCache(java.lang.String filePath)restore cache from file | 
| CacheObject<V> | put(K key,
   CacheObject<V> value)put element, key and value both not allowed to be null | 
| CacheObject<V> | put(K key,
   V value)put element, key not allowed to be null | 
| void | putAll(Cache<K,V> cache2)pull all elements of cache2 to this | 
| CacheObject<V> | remove(K key)remove the specified key from cache, key not allowed to be null | 
| static <K,V> void | saveCache(java.lang.String filePath,
         SimpleCache<K,V> cache)save cache to file, the data of  CacheObjectshould can be serializabled | 
| void | setCacheFullRemoveType(CacheFullRemoveType<V> cacheFullRemoveType)set remove type when cache is full | 
| void | setValidTime(long validTime)set valid time of elements in cache, in mills | 
| java.util.Collection<CacheObject<V>> | values()value set | 
public static final int DEFAULT_MAX_SIZE
public SimpleCache()
DEFAULT_MAX_SIZEsetValidTime(long)RemoveTypeEnterTimeFirst when cache is fullpublic SimpleCache(int maxSize)
setValidTime(long)RemoveTypeEnterTimeFirst when cache is fullmaxSize - maximum size of the cachepublic int getMaxSize()
public long getValidTime()
public void setValidTime(long validTime)
validTime - valid time of elements in cache, in mills. If less than 0, it will be set to -1 and means not
 invalid. Rule of invalid see isExpired(CacheObject)public CacheFullRemoveType<V> getCacheFullRemoveType()
public void setCacheFullRemoveType(CacheFullRemoveType<V> cacheFullRemoveType)
cacheFullRemoveType - the cacheFullRemoveType to setpublic int getSize()
public CacheObject<V> get(K key)
public CacheObject<V> put(K key, V value)
put in interface Cache<K,V>key - keyvalue - data of CacheObjectput(Object, CacheObject)public CacheObject<V> put(K key, CacheObject<V> value)
public boolean containsKey(K key)
containsKey in interface Cache<K,V>key - public CacheObject<V> remove(K key)
public void clear()
public long getHitCount()
public long getMissCount()
public double getHitRate()
getHitRate in interface Cache<K,V>public java.util.Set<java.util.Map.Entry<K,CacheObject<V>>> entrySet()
Cachepublic java.util.Collection<CacheObject<V>> values()
Cachepublic static <K,V> SimpleCache<K,V> loadCache(java.lang.String filePath)
filePath - public static <K,V> void saveCache(java.lang.String filePath,
                   SimpleCache<K,V> cache)
CacheObject should can be serializabledK - V - filePath - cache -