fabric.common.util
Class Cache<K,V>

java.lang.Object
  extended by fabric.common.util.Cache<K,V>

public class Cache<K,V>
extends java.lang.Object

A thread-safe map with soft references to its values. When a value in the map is garbage collected by the JVM, its corresponding key is removed from the map.


Nested Class Summary
static class Cache.Collector
           
 
Constructor Summary
Cache()
           
 
Method Summary
 void clear()
           
 boolean containsKey(K key)
           
 V get(K key)
           
 java.util.Set<K> keys()
          Returns a snapshot of the keys currently in the cache.
 V put(K key, V value)
           
 V remove(java.lang.Object key)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cache

public Cache()
Method Detail

clear

public void clear()

containsKey

public boolean containsKey(K key)

get

public V get(K key)

put

public V put(K key,
             V value)

remove

public V remove(java.lang.Object key)

keys

public java.util.Set<K> keys()
Returns a snapshot of the keys currently in the cache. This set is NOT backed by the underlying map. If new keys are inserted or removed from the cache, they will not be reflected by the set returned. However, no synchronization is needed for working with the set.