Package org.compiere.util
Class CCache<K,V>
- java.lang.Object
-
- org.compiere.util.CCache<K,V>
-
- Type Parameters:
K- KeyV- Value
- All Implemented Interfaces:
Serializable,Map<K,V>,CacheInterface
- Direct Known Subclasses:
ImmutablePOCache,NaturalAccountMap,POCopyCache
public class CCache<K,V> extends Object implements CacheInterface, Map<K,V>, Serializable
Cache for table.- Version:
- $Id: CCache.java,v 1.2 2006/07/30 00:54:35 jjanke Exp $
- Author:
- Jorg Janke
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CCache(String name, int initialCapacity)CCache(String name, int initialCapacity, int expireMinutes)CCache(String name, int initialCapacity, int expireMinutes, boolean distributed)CCache(String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize)CCache(String tableName, String name, int initialCapacity)Adempiere Cache - expires after 2 hoursCCache(String tableName, String name, int initialCapacity, boolean distributed)CCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed)CCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize)Adempiere Cache
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddVetoableChangeListener(VetoableChangeListener listener)Add Vetoable Change Listenervoidclear()Clear cache and calculate new expiry timebooleancontainsKey(Object key)booleancontainsValue(Object value)Set<Map.Entry<K,V>>entrySet()The return entry set exclude entries that contains null valueVget(Object key)intgetExpireMinutes()Get Expire MinuteslonggetHit()intgetMaxSize()longgetMiss()StringgetName()Get (table) NameStringgetTableName()booleanisDistributed()booleanisEmpty()booleanisExpire()booleanisReset()Cache was resetSet<K>keySet()The return key set excludes key that map to null valuevoidnewRecord(int record_ID)New record created notificationVput(K key, V value)Put valuevoidputAll(Map<? extends K,? extends V> m)Put AllVremove(Object key)voidremoveVetoableChangeListener(VetoableChangeListener listener)Remove Vetoable Change Listenerintreset()Reset Cacheintreset(int recordId)Reset Cache by record idvoidsetExpireMinutes(int expireMinutes)Set Expire Minutes and start itvoidsetUsed()Resets the Reset flagintsize()Get Size of CacheintsizeNoExpire()Get Size w/o ExpireStringtoString()String RepresentationCollection<V>values()The return values collection exclude null value entries-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
CCache
public CCache(String name, int initialCapacity)
-
CCache
public CCache(String name, int initialCapacity, int expireMinutes)
-
CCache
public CCache(String name, int initialCapacity, int expireMinutes, boolean distributed)
-
CCache
public CCache(String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize)
-
CCache
public CCache(String tableName, String name, int initialCapacity)
Adempiere Cache - expires after 2 hours- Parameters:
name- (table) name of the cacheinitialCapacity- initial capacity
-
CCache
public CCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed)
-
CCache
public CCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize)
Adempiere Cache- Parameters:
name- (table) name of the cacheinitialCapacity- initial capacityexpireMinutes- expire after minutes (0=no expire)distributed-maxSize- ignore if distributed=true
-
-
Method Detail
-
getName
public String getName()
Get (table) Name- Returns:
- name
-
getTableName
public String getTableName()
-
setExpireMinutes
public void setExpireMinutes(int expireMinutes)
Set Expire Minutes and start it- Parameters:
expireMinutes- minutes or 0
-
getExpireMinutes
public int getExpireMinutes()
Get Expire Minutes- Returns:
- expire minutes
-
isReset
public boolean isReset()
Cache was reset- Returns:
- true if reset
-
setUsed
public void setUsed()
Resets the Reset flag
-
reset
public int reset()
Reset Cache- Specified by:
resetin interfaceCacheInterface- Returns:
- number of items cleared
- See Also:
CacheInterface.reset()
-
toString
public String toString()
String Representation
-
clear
public void clear()
Clear cache and calculate new expiry time- Specified by:
clearin interfaceMap<K,V>- See Also:
Map.clear()
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<K,V>- See Also:
Map.containsKey(java.lang.Object)
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<K,V>- See Also:
Map.containsValue(java.lang.Object)
-
entrySet
public Set<Map.Entry<K,V>> entrySet()
The return entry set exclude entries that contains null value- Specified by:
entrySetin interfaceMap<K,V>- See Also:
Map.entrySet()
-
get
public V get(Object key)
- Specified by:
getin interfaceMap<K,V>- See Also:
Map.get(java.lang.Object)
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceMap<K,V>- See Also:
Map.isEmpty()
-
keySet
public Set<K> keySet()
The return key set excludes key that map to null value- Specified by:
keySetin interfaceMap<K,V>- See Also:
Map.keySet()
-
size
public int size()
Description copied from interface:CacheInterfaceGet Size of Cache- Specified by:
sizein interfaceCacheInterface- Specified by:
sizein interfaceMap<K,V>- Returns:
- number of items
- See Also:
Map.size()
-
sizeNoExpire
public int sizeNoExpire()
Get Size w/o Expire- Returns:
- size
- See Also:
Map.size()
-
values
public Collection<V> values()
The return values collection exclude null value entries- Specified by:
valuesin interfaceMap<K,V>- See Also:
Map.values()
-
addVetoableChangeListener
public void addVetoableChangeListener(VetoableChangeListener listener)
Add Vetoable Change Listener- Parameters:
listener- listner
-
removeVetoableChangeListener
public void removeVetoableChangeListener(VetoableChangeListener listener)
Remove Vetoable Change Listener- Parameters:
listener- listener
-
reset
public int reset(int recordId)
Description copied from interface:CacheInterfaceReset Cache by record id- Specified by:
resetin interfaceCacheInterface- Returns:
- number of items reset
-
newRecord
public void newRecord(int record_ID)
Description copied from interface:CacheInterfaceNew record created notification- Specified by:
newRecordin interfaceCacheInterface
-
getMaxSize
public int getMaxSize()
- Returns:
- max size of cache
-
isDistributed
public boolean isDistributed()
- Returns:
- true if cache is distributed (using hazelcast)
-
getHit
public long getHit()
- Returns:
- cache hit count
-
getMiss
public long getMiss()
- Returns:
- cache miss count
-
isExpire
public boolean isExpire()
- Returns:
- true if cache has expire
-
-