Class ImmutablePOCache<K,​V extends PO & ImmutablePOSupport>

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

        public ImmutablePOCache​(String tableName,
                                String name,
                                int initialCapacity)
        Parameters:
        tableName -
        name -
        initialCapacity -
    • 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​(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)