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
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:
-
Nested Class Summary
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate new cache instance and register withCacheMgtCreate new cache instance and register withCacheMgtCreate new cache instance and register withCacheMgtCreate new cache instance and register withCacheMgtCreate new cache instance and register withCacheMgtCreate new cache instance and register withCacheMgtCreate new cache instance and register withCacheMgtCCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize) Create new cache instance and register withCacheMgt -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd Vetoable Change Listenervoidclear()Clear cache and calculate new expire timebooleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()The return entry set exclude entries that contains null valueintGet Expire MinuteslonggetHit()Get cache hit countintGet maximum size of cachelonggetMiss()Get cache miss countgetName()Get (table) NameGet table namebooleanIs cache distributedbooleanisEmpty()booleanisExpire()booleanisReset()Cache was resetkeySet()The return key set excludes key that map to null valuevoidnewRecord(int record_ID) New record created notificationPut valuevoidPut AllvoidRemove Vetoable Change Listenerintreset()Reset Cacheintreset(int recordId) Reset Cache by record idintresetByStringKey(String key) Reset Cache by String keyvoidsetExpireMinutes(int expireMinutes) Set Expire Minutes and start itvoidsetUsed()Resets the Reset flagintsize()Get Size of CacheintGet Size w/o ExpiretoString()String Representationvalues()The return values collection exclude null value entriesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
cache
Key:value map of cached items -
nullList
Set of key that has null value -
DEFAULT_EXPIRE_MINUTE
public static final int DEFAULT_EXPIRE_MINUTEDefault cache expire time in minutes
-
-
Constructor Details
-
CCache
Create new cache instance and register withCacheMgt- Parameters:
name-initialCapacity-
-
CCache
Create new cache instance and register withCacheMgt- Parameters:
name-initialCapacity-expireMinutes-
-
CCache
Create new cache instance and register withCacheMgt- Parameters:
name-initialCapacity-expireMinutes-distributed-
-
CCache
public CCache(String name, int initialCapacity, int expireMinutes, boolean distributed, int maxSize) Create new cache instance and register withCacheMgt- Parameters:
name-initialCapacity-expireMinutes-distributed-maxSize-
-
CCache
Create new cache instance and register withCacheMgt- Parameters:
tableName-name- (table) name of the cacheinitialCapacity- initial capacity // ignored
-
CCache
Create new cache instance and register withCacheMgt- Parameters:
tableName-name-initialCapacity-distributed-
-
CCache
public CCache(String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed) Create new cache instance and register withCacheMgt- 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 withCacheMgt- Parameters:
tableName-name- (table) name of the cacheinitialCapacity- initial capacity // ignoredexpireMinutes- expire after minutes (0=no expire)distributed- true if cache should be distributed across server nodesmaxSize- ignore if distributed=true (0=no max size)
-
-
Method Details
-
getName
Get (table) Name- Returns:
- name
-
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:
resetin interfaceCacheInterface- Returns:
- number of items cleared
- See Also:
-
toString
String Representation -
clear
public void clear()Clear cache and calculate new expire time -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - See Also:
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V> - See Also:
-
entrySet
The return entry set exclude entries that contains null value -
get
-
put
Put value -
putAll
Put All -
isEmpty
public boolean isEmpty() -
keySet
The return key set excludes key that map to null value -
size
public int size()Description copied from interface:CacheInterfaceGet Size of Cache -
sizeNoExpire
public int sizeNoExpire()Get Size w/o Expire- Returns:
- size
- See Also:
-
values
The return values collection exclude null value entries -
addVetoableChangeListener
Add Vetoable Change Listener- Parameters:
listener- listner
-
removeVetoableChangeListener
Remove Vetoable Change Listener- Parameters:
listener- listener
-
remove
-
reset
public int reset(int recordId) Description copied from interface:CacheInterfaceReset Cache by record id- Specified by:
resetin interfaceCacheInterface- Returns:
- number of items reset
-
resetByStringKey
Description copied from interface:CacheInterfaceReset Cache by String key- Specified by:
resetByStringKeyin interfaceCacheInterface- Returns:
- number of items reset
-
newRecord
public void newRecord(int record_ID) Description copied from interface:CacheInterfaceNew record created notification- Specified by:
newRecordin interfaceCacheInterface
-
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
-