org.omnaest.utils.cache
Class SynchronizedWeakReferenceCache<K,V>

java.lang.Object
  extended by org.omnaest.utils.cache.SynchronizedWeakReferenceCache<K,V>
Type Parameters:
K -
V -
All Implemented Interfaces:
Serializable, Map<K,V>, Cache<K,V>

public class SynchronizedWeakReferenceCache<K,V>
extends Object

Cache implementation using a synchronized WeakHashMap. It is thread safe but has a bad performance in concurrent access situations. Stored elements can vanish at any time the underlying JVM decides to clear them.

Author:
Omnaest
See Also:
ConcurrentWeakReferenceCache, Cache, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
SynchronizedWeakReferenceCache()
           
 
Method Summary
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<K,V>> entrySet()
          Returns an unmodifiable Set of all Map.Entrys within the Cache which only represents a snapshot in moment
 boolean equals(Object o)
           
 V get(Object key)
           
 V getOrCreate(K key, Factory<V> factory)
          Gets a cached value or creates a new one using the given Factory and puts the new value into the cache.
 int hashCode()
           
 boolean isEmpty()
           
 Set<K> keySet()
          Returns an unmodifiable Set of all keys within the Cache which only represents a snapshot in moment
 V put(K key, V value)
           
 void putAll(Map<? extends K,? extends V> m)
           
 V remove(Object key)
           
 int size()
           
 Collection<V> values()
          Returns an unmodifiable Collection of all values within the Cache which only represents a snapshot in moment
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SynchronizedWeakReferenceCache

public SynchronizedWeakReferenceCache()
Method Detail

size

public int size()

isEmpty

public boolean isEmpty()

containsKey

public boolean containsKey(Object key)

containsValue

public boolean containsValue(Object value)

get

public V get(Object key)

put

public V put(K key,
             V value)

remove

public V remove(Object key)

putAll

public void putAll(Map<? extends K,? extends V> m)

clear

public void clear()

keySet

public Set<K> keySet()
Description copied from interface: Cache
Returns an unmodifiable Set of all keys within the Cache which only represents a snapshot in moment


values

public Collection<V> values()
Description copied from interface: Cache
Returns an unmodifiable Collection of all values within the Cache which only represents a snapshot in moment


entrySet

public Set<Map.Entry<K,V>> entrySet()
Description copied from interface: Cache
Returns an unmodifiable Set of all Map.Entrys within the Cache which only represents a snapshot in moment


equals

public boolean equals(Object o)
Specified by:
equals in interface Map<K,V>
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Map<K,V>
Overrides:
hashCode in class Object

getOrCreate

public V getOrCreate(K key,
                     Factory<V> factory)
Description copied from interface: Cache
Gets a cached value or creates a new one using the given Factory and puts the new value into the cache.

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


Copyright © 2013. All Rights Reserved.