Package org.idempiere.cache
Class ImmutablePOCache<K,V extends PO & ImmutablePOSupport>
- java.lang.Object
-
- org.compiere.util.CCache<K,V>
-
- org.idempiere.cache.ImmutablePOCache<K,V>
-
- All Implemented Interfaces:
Serializable
,Map<K,V>
,CacheInterface
- Direct Known Subclasses:
ImmutableIntPOCache
public class ImmutablePOCache<K,V extends PO & ImmutablePOSupport> extends CCache<K,V>
Thread safe PO cache. For thread safety, only PO with thread local context (po.getCtx() == Env.getCtx() and without trxName is keep in cache. PO is mark immutable before being added to cache. If the pass in PO doesn't match the 2 condition, a copy of the PO is added to cache instead. For get operation, if request is being make with non thread local context (ctx != Env.getCtx()) or with trxName, a copy of the PO from cache is return instead.- Author:
- hengsin
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.compiere.util.CCache
cache, DEFAULT_EXPIRE_MINUTE, nullList
-
-
Constructor Summary
Constructors Constructor Description ImmutablePOCache(String name, int initialCapacity)
ImmutablePOCache(String name, int initialCapacity, int expireMinutes)
ImmutablePOCache(String name, int initialCapacity, int expireMinutes, boolean distributed)
ImmutablePOCache(String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize)
ImmutablePOCache(String tableName, String name, int initialCapacity)
ImmutablePOCache(String tableName, String name, int initialCapacity, boolean distributed)
ImmutablePOCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed)
ImmutablePOCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description V
get(Object key)
V
get(Properties ctx, K key)
V
get(Properties ctx, K key, UnaryOperator<V> copyOperator)
Get PO from cache.V
put(K key, V value)
Put valueV
put(K key, V po, UnaryOperator<V> copyOperator)
PO is mark immutable and add to cache if it is without trxName and with thread local context (i.e po.getCtx() == Env.getCtx()).-
Methods inherited from class org.compiere.util.CCache
addVetoableChangeListener, clear, containsKey, containsValue, entrySet, getExpireMinutes, getHit, getMaxSize, getMiss, getName, getTableName, isDistributed, isEmpty, isExpire, isReset, keySet, newRecord, putAll, remove, removeVetoableChangeListener, reset, reset, setExpireMinutes, setUsed, size, sizeNoExpire, toString, values
-
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
-
ImmutablePOCache
public ImmutablePOCache(String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize)
- Parameters:
name
-initialCapacity
-expireMinutes
-distributed
-maxSize
-
-
ImmutablePOCache
public ImmutablePOCache(String name, int initialCapacity, int expireMinutes, boolean distributed)
- Parameters:
name
-initialCapacity
-expireMinutes
-distributed
-
-
ImmutablePOCache
public ImmutablePOCache(String name, int initialCapacity, int expireMinutes)
- Parameters:
name
-initialCapacity
-expireMinutes
-
-
ImmutablePOCache
public ImmutablePOCache(String name, int initialCapacity)
- Parameters:
name
-initialCapacity
-
-
ImmutablePOCache
public ImmutablePOCache(String tableName, String name, int initialCapacity, boolean distributed)
- Parameters:
tableName
-name
-initialCapacity
-distributed
-
-
ImmutablePOCache
public ImmutablePOCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize)
- Parameters:
tableName
-name
-initialCapacity
-expireMinutes
-distributed
-maxSize
-
-
ImmutablePOCache
public ImmutablePOCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed)
- Parameters:
tableName
-name
-initialCapacity
-expireMinutes
-distributed
-
-
-
Method Detail
-
put
public V put(K key, V po, UnaryOperator<V> copyOperator)
PO is mark immutable and add to cache if it is without trxName and with thread local context (i.e po.getCtx() == Env.getCtx()). If neither of the condition is not true, a copy of the PO will be created and add to cache using the pass copyOperator or through copy constructor (through reflection) if copyOperator parameter is null (exception is throw if both copyOperator and copy constructor is not available).- Parameters:
key
-po
-copyOperator
- operator to call copy constructor if po has transaction name or po.getCtx() != Env.getCtx()- Returns:
- po or the copy of po that have been added to cache
-
get
public V get(Object key)
- Specified by:
get
in interfaceMap<K,V extends PO & ImmutablePOSupport>
- Overrides:
get
in classCCache<K,V extends PO & ImmutablePOSupport>
- See Also:
Map.get(java.lang.Object)
-
get
public V get(Properties ctx, K key)
- Parameters:
ctx
- contextkey
-- Returns:
- value for key
-
get
public V get(Properties ctx, K key, UnaryOperator<V> copyOperator)
Get PO from cache. If ctx != Env.getCtx() or trxName is not empty, a copy of the PO is return instead- Parameters:
ctx
- contextkey
-copyOperator
- operator to call copy constructor when ctx != po.getCtx() or transaction name is not empty- Returns:
- PO from cache (if there's match for key)
-
-