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 void
addVetoableChangeListener(VetoableChangeListener listener)
Add Vetoable Change Listenervoid
clear()
Clear cache and calculate new expiry timeboolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<K,V>>
entrySet()
The return entry set exclude entries that contains null valueV
get(Object key)
int
getExpireMinutes()
Get Expire Minuteslong
getHit()
int
getMaxSize()
long
getMiss()
String
getName()
Get (table) NameString
getTableName()
boolean
isDistributed()
boolean
isEmpty()
boolean
isExpire()
boolean
isReset()
Cache was resetSet<K>
keySet()
The return key set excludes key that map to null valuevoid
newRecord(int record_ID)
New record created notificationV
put(K key, V value)
Put valuevoid
putAll(Map<? extends K,? extends V> m)
Put AllV
remove(Object key)
void
removeVetoableChangeListener(VetoableChangeListener listener)
Remove Vetoable Change Listenerint
reset()
Reset Cacheint
reset(int recordId)
Reset Cache by record idvoid
setExpireMinutes(int expireMinutes)
Set Expire Minutes and start itvoid
setUsed()
Resets the Reset flagint
size()
Get Size of Cacheint
sizeNoExpire()
Get Size w/o ExpireString
toString()
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:
reset
in 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:
clear
in interfaceMap<K,V>
- See Also:
Map.clear()
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
- See Also:
Map.containsKey(java.lang.Object)
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in 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:
entrySet
in interfaceMap<K,V>
- See Also:
Map.entrySet()
-
get
public V get(Object key)
- Specified by:
get
in interfaceMap<K,V>
- See Also:
Map.get(java.lang.Object)
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in 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:
keySet
in interfaceMap<K,V>
- See Also:
Map.keySet()
-
size
public int size()
Description copied from interface:CacheInterface
Get Size of Cache- Specified by:
size
in interfaceCacheInterface
- Specified by:
size
in 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:
values
in 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:CacheInterface
Reset Cache by record id- Specified by:
reset
in interfaceCacheInterface
- Returns:
- number of items reset
-
newRecord
public void newRecord(int record_ID)
Description copied from interface:CacheInterface
New record created notification- Specified by:
newRecord
in 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
-
-