Compiere 3.1

org.compiere.util
Class CCache<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.concurrent.ConcurrentHashMap<K,V>
          extended by org.compiere.util.CCache<K,V>
Type Parameters:
K - Key
V - Value
All Implemented Interfaces:
Serializable, ConcurrentMap<K,V>, Map<K,V>, CacheInterface
Direct Known Subclasses:
NaturalAccountMap

public class CCache<K,V>
extends ConcurrentHashMap<K,V>
implements CacheInterface

Compiere Cache.

Version:
$Id: CCache.java,v 1.2 2006/07/30 00:54:35 jjanke Exp $
Author:
Jorg Janke
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
CCache(String name, int initialCapacity)
          Compiere Cache - expires after 2 hours
CCache(String name, int initialCapacity, int expireMinutes)
          Compiere Cache
 
Method Summary
 void addVetoableChangeListener(VetoableChangeListener listener)
          Add Vetoable Change Listener
 void clear()
          Clear cache and calculate new expiry time
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Ctx ctx, Object key)
          Get cached object
 V get(Object key)
          Deprecated. 
 int getExpireMinutes()
          Get Expire Minutes
 String getName()
          Get (table) Name
 boolean isEmpty()
           
 boolean isReset()
          Cache was reset
 Set<K> keySet()
           
 V put(K key, V value)
          Put value
 void putAll(Map<? extends K,? extends V> m)
          Put All
 void removeVetoableChangeListener(VetoableChangeListener listener)
          Remove Vetoable Change Listener
 int reset()
          Reset Cache
 void setExpireMinutes(int expireMinutes)
          Set Expire Minutes and start it
 void setUsed()
          Resets the Reset flag
 int size()
          Get Size of Cache
 int sizeNoExpire()
          Get Size w/o Expire
 String toString()
          String Representation
 Collection<V> values()
           
 
Methods inherited from class java.util.concurrent.ConcurrentHashMap
contains, elements, keys, putIfAbsent, remove, remove, replace, replace
 
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

CCache

public CCache(String name,
              int initialCapacity)
Compiere Cache - expires after 2 hours

Parameters:
name - (table) name of the cache
initialCapacity - initial capacity

CCache

public CCache(String name,
              int initialCapacity,
              int expireMinutes)
Compiere Cache

Parameters:
name - (table) name of the cache
initialCapacity - initial capacity
expireMinutes - expire after minutes (0=no expire)
Method Detail

getName

public String getName()
Get (table) Name

Returns:
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:
CacheInterface.reset()

toString

public String toString()
String Representation

Overrides:
toString in class AbstractMap<K,V>
Returns:
info

clear

public void clear()
Clear cache and calculate new expiry time

Specified by:
clear in interface Map<K,V>
Overrides:
clear in class ConcurrentHashMap<K,V>
See Also:
Map.clear()

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class ConcurrentHashMap<K,V>
See Also:
Map.containsKey(java.lang.Object)

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>
Overrides:
containsValue in class ConcurrentHashMap<K,V>
See Also:
Map.containsValue(java.lang.Object)

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
Overrides:
entrySet in class ConcurrentHashMap<K,V>
See Also:
Map.entrySet()

get

@Deprecated
public V get(Object key)
Deprecated. 

Use get(Ctx, key)

Specified by:
get in interface Map<K,V>
Overrides:
get in class ConcurrentHashMap<K,V>
See Also:
Map.get(java.lang.Object)

get

public V get(Ctx ctx,
             Object key)
Get cached object

Parameters:
ctx - context (only used when the cached object is a PO - otherwise ignored)
key - the key value
Returns:
cached value or if PO and ctx provided, the clone of a PO
See Also:
Map.get(java.lang.Object)

put

public V put(K key,
             V value)
Put value

Specified by:
put in interface Map<K,V>
Overrides:
put in class ConcurrentHashMap<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>
Overrides:
putAll in class ConcurrentHashMap<K,V>
Parameters:
m - map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>
Overrides:
isEmpty in class ConcurrentHashMap<K,V>
See Also:
Map.isEmpty()

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class ConcurrentHashMap<K,V>
See Also:
Map.keySet()

size

public int size()
Description copied from interface: CacheInterface
Get Size of Cache

Specified by:
size in interface Map<K,V>
Specified by:
size in interface CacheInterface
Overrides:
size in class ConcurrentHashMap<K,V>
Returns:
number of items
See Also:
Map.size()

sizeNoExpire

public int sizeNoExpire()
Get Size w/o Expire

Returns:
size
See Also:
Map.size()

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>
Overrides:
values in class ConcurrentHashMap<K,V>
See Also:
Map.values()

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

Compiere 3.1

Compiere® is a registered trademark of ComPiere, Inc. ©2004-2008 HumanFlash.com All rights reserved.