org.teiid.cache
Class DefaultCache<K,V>

java.lang.Object
  extended by org.teiid.cache.DefaultCache<K,V>
All Implemented Interfaces:
java.io.Serializable, Cache<K,V>

public class DefaultCache<K,V>
extends java.lang.Object
implements Cache<K,V>, java.io.Serializable

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.teiid.cache.Cache
Cache.Type
 
Field Summary
protected  java.util.Map<java.lang.String,Cache> children
           
static int DEFAULT_MAX_AGE
           
static int DEFAULT_MAX_SIZE_TOTAL
           
protected  java.util.LinkedHashSet<org.teiid.cache.DefaultCache.ExpirationEntry<K,V>> expirationQueue
           
protected  LRUCache<K,org.teiid.cache.DefaultCache.ExpirationEntry<K,V>> map
           
protected  java.lang.String name
           
protected  long ttl
           
 
Constructor Summary
DefaultCache(java.lang.String name)
           
DefaultCache(java.lang.String name, int maxEntries, long ttl)
           
 
Method Summary
 Cache addChild(java.lang.String name)
           
 void addListener(CacheListener listener)
           
 void clear()
          Removes all the keys and their values from the Cache
 V get(K key)
          Retrieves the value for the given Key
 Cache getChild(java.lang.String name)
           
 java.util.Collection<Cache> getChildren()
           
static long getExpirationTime(long defaultTtl, java.lang.Long ttl)
           
 java.lang.String getName()
          Name of the cache node
 java.util.Set<K> keySet()
           
 V put(K key, V value)
           
 V put(K key, V value, java.lang.Long timeToLive)
          Associates the specified value with the specified key this cache.
 V remove(K key)
          Removes the value for this key from a Cache.
 boolean removeChild(java.lang.String name)
           
 int size()
          Size of the cache
 java.util.Collection<V> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_SIZE_TOTAL

public static final int DEFAULT_MAX_SIZE_TOTAL
See Also:
Constant Field Values

DEFAULT_MAX_AGE

public static final int DEFAULT_MAX_AGE
See Also:
Constant Field Values

map

protected LRUCache<K,org.teiid.cache.DefaultCache.ExpirationEntry<K,V>> map

children

protected java.util.Map<java.lang.String,Cache> children

name

protected java.lang.String name

ttl

protected long ttl

expirationQueue

protected java.util.LinkedHashSet<org.teiid.cache.DefaultCache.ExpirationEntry<K,V>> expirationQueue
Constructor Detail

DefaultCache

public DefaultCache(java.lang.String name)

DefaultCache

public DefaultCache(java.lang.String name,
                    int maxEntries,
                    long ttl)
Method Detail

addListener

public void addListener(CacheListener listener)

clear

public void clear()
Description copied from interface: Cache
Removes all the keys and their values from the Cache

Specified by:
clear in interface Cache<K,V>

get

public V get(K key)
Description copied from interface: Cache
Retrieves the value for the given Key

Specified by:
get in interface Cache<K,V>
Parameters:
key - key under which value is to be retrieved.
Returns:
returns data held under specified key in cache

keySet

public java.util.Set<K> keySet()

put

public V put(K key,
             V value)

getExpirationTime

public static long getExpirationTime(long defaultTtl,
                                     java.lang.Long ttl)

put

public V put(K key,
             V value,
             java.lang.Long timeToLive)
Description copied from interface: Cache
Associates the specified value with the specified key this cache. If the cache previously contained a mapping for this key, the old value is replaced by the specified value.

Specified by:
put in interface Cache<K,V>
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
timeToLive - the time for this entry to live
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the key previously associated null with the specified key, if the implementation supports null values.

remove

public V remove(K key)
Description copied from interface: Cache
Removes the value for this key from a Cache. Returns the value to which the Key previously associated , or null if the Key contained no mapping.

Specified by:
remove in interface Cache<K,V>
Parameters:
key - key whose mapping is to be removed
Returns:
previous value associated with specified Node's key

size

public int size()
Description copied from interface: Cache
Size of the cache

Specified by:
size in interface Cache<K,V>
Returns:
number of items in this cache

values

public java.util.Collection<V> values()

addChild

public Cache addChild(java.lang.String name)

getChild

public Cache getChild(java.lang.String name)

getChildren

public java.util.Collection<Cache> getChildren()

removeChild

public boolean removeChild(java.lang.String name)

getName

public java.lang.String getName()
Description copied from interface: Cache
Name of the cache node

Specified by:
getName in interface Cache<K,V>
Returns:


Copyright © 2010. All Rights Reserved.