public class WeakCache<K,V> extends java.lang.Object implements Cache<K,V>
WeakCache
object is an implementation of a cache
that holds on to cached items only if the key remains in memory.
This is effectively like a concurrent hash map with weak keys, it
ensures that multiple threads can concurrently access weak hash
maps in a way that lowers contention for the locks used.Constructor and Description |
---|
WeakCache()
Constructor for the
WeakCache object. |
WeakCache(int size)
Constructor for the
WeakCache object. |
Modifier and Type | Method and Description |
---|---|
void |
cache(K key,
V value)
This method is used to insert a key value mapping in to the
cache.
|
boolean |
contains(K key)
This is used to determine whether the specified key exists
with in the cache.
|
V |
fetch(K key)
This method is used to get the value from the cache that is
mapped to the specified key.
|
V |
take(K key)
This is used to exclusively take the value mapped to the
specified key from the cache.
|
public WeakCache()
WeakCache
object. This is
used to create a cache that stores values in such a way that
when the key is garbage collected the value is removed from
the map. This is similar to the concurrent hash map.public WeakCache(int size)
WeakCache
object. This is
used to create a cache that stores values in such a way that
when the key is garbage collected the value is removed from
the map. This is similar to the concurrent hash map.size
- this is the number of segments within the cachepublic void cache(K key, V value)
public V take(K key)
public V fetch(K key)
public boolean contains(K key)