Class CCache<K,V>

java.lang.Object
org.compiere.util.CCache<K,V>
Type Parameters:
K - Key
V - 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
Default cache implementation, usually use for caching of table data.
Version:
$Id: CCache.java,v 1.2 2006/07/30 00:54:35 jjanke Exp $
Author:
Jorg Janke
See Also:
  • Field Details

    • cache

      protected Map<K,V> cache
      Key:value map of cached items
    • nullList

      protected Set<K> nullList
      Set of key that has null value
    • DEFAULT_EXPIRE_MINUTE

      public static final int DEFAULT_EXPIRE_MINUTE
      Default cache expire time in minutes
  • Constructor Details

    • CCache

      public CCache(String name, int initialCapacity)
      Create new cache instance and register with CacheMgt
      Parameters:
      name -
      initialCapacity -
    • CCache

      public CCache(String name, int initialCapacity, int expireMinutes)
      Create new cache instance and register with CacheMgt
      Parameters:
      name -
      initialCapacity -
      expireMinutes -
    • CCache

      public CCache(String name, int initialCapacity, int expireMinutes, boolean distributed)
      Create new cache instance and register with CacheMgt
      Parameters:
      name -
      initialCapacity -
      expireMinutes -
      distributed -
    • CCache

      public CCache(String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize)
      Create new cache instance and register with CacheMgt
      Parameters:
      name -
      initialCapacity -
      expireMinutes -
      distributed -
      maxSize -
    • CCache

      public CCache(String tableName, String name, int initialCapacity)
      Create new cache instance and register with CacheMgt
      Parameters:
      tableName -
      name - (table) name of the cache
      initialCapacity - initial capacity // ignored
    • CCache

      public CCache(String tableName, String name, int initialCapacity, boolean distributed)
      Create new cache instance and register with CacheMgt
      Parameters:
      tableName -
      name -
      initialCapacity -
      distributed -
    • CCache

      public CCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed)
      Create new cache instance and register with CacheMgt
      Parameters:
      tableName -
      name -
      initialCapacity -
      expireMinutes -
      distributed -
    • CCache

      public CCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize)
      Create new cache instance and register with CacheMgt
      Parameters:
      tableName -
      name - (table) name of the cache
      initialCapacity - initial capacity // ignored
      expireMinutes - expire after minutes (0=no expire)
      distributed - true if cache should be distributed across server nodes
      maxSize - ignore if distributed=true (0=no max size)
  • Method Details

    • getName

      public String getName()
      Get (table) Name
      Returns:
      name
    • getTableName

      public String getTableName()
      Get table name
      Returns:
      table name
    • 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 interface CacheInterface
      Returns:
      number of items cleared
      See Also:
    • toString

      public String toString()
      String Representation
      Overrides:
      toString in class Object
      Returns:
      info
    • clear

      public void clear()
      Clear cache and calculate new expire time
      Specified by:
      clear in interface Map<K,V>
      See Also:
    • containsKey

      public boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K,V>
      See Also:
    • containsValue

      public boolean containsValue(Object value)
      Specified by:
      containsValue in interface Map<K,V>
      See Also:
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      The return entry set exclude entries that contains null value
      Specified by:
      entrySet in interface Map<K,V>
      See Also:
    • get

      public V get(Object key)
      Specified by:
      get in interface Map<K,V>
      See Also:
    • put

      public V put(K key, V value)
      Put value
      Specified by:
      put in interface Map<K,V>
      Parameters:
      key - key
      value - value
      Returns:
      previous value
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Put All
      Specified by:
      putAll in interface Map<K,V>
      Parameters:
      m - map
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
      See Also:
    • keySet

      public Set<K> keySet()
      The return key set excludes key that map to null value
      Specified by:
      keySet in interface Map<K,V>
      See Also:
    • size

      public int size()
      Description copied from interface: CacheInterface
      Get Size of Cache
      Specified by:
      size in interface CacheInterface
      Specified by:
      size in interface Map<K,V>
      Returns:
      number of items
      See Also:
    • sizeNoExpire

      public int sizeNoExpire()
      Get Size w/o Expire
      Returns:
      size
      See Also:
    • values

      public Collection<V> values()
      The return values collection exclude null value entries
      Specified by:
      values in interface Map<K,V>
      See Also:
    • 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
    • remove

      public V remove(Object key)
      Specified by:
      remove in interface Map<K,V>
    • reset

      public int reset(int recordId)
      Description copied from interface: CacheInterface
      Reset Cache by record id
      Specified by:
      reset in interface CacheInterface
      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 interface CacheInterface
    • getMaxSize

      public int getMaxSize()
      Get maximum size of cache
      Returns:
      max size of cache
    • isDistributed

      public boolean isDistributed()
      Is cache distributed
      Returns:
      true if cache is distributed (using hazelcast)
    • getHit

      public long getHit()
      Get cache hit count
      Returns:
      cache hit count
    • getMiss

      public long getMiss()
      Get cache miss count
      Returns:
      cache miss count
    • isExpire

      public boolean isExpire()
      Returns:
      true if cache has expire