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:
  • Constructor Details

    • 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 -
    • ImmutablePOCache

      public ImmutablePOCache(String tableName, String name, int initialCapacity)
      Parameters:
      tableName -
      name -
      initialCapacity -
  • Method Details

    • put

      public V put(K key, V value)
      Description copied from class: CCache
      Put value
      Specified by:
      put in interface Map<K,V extends PO & ImmutablePOSupport>
      Overrides:
      put in class CCache<K,V extends PO & ImmutablePOSupport>
      Parameters:
      key - key
      value - value
      Returns:
      previous value
    • 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 either of the condition is not true, a copy of the PO will be created and add to cache using the pass in 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 interface Map<K,V extends PO & ImmutablePOSupport>
      Overrides:
      get in class CCache<K,V extends PO & ImmutablePOSupport>
      See Also:
    • get

      public V get(Properties ctx, K key)
      Parameters:
      ctx - context
      key -
      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 - context
      key -
      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)