public class WeakCache<T> extends Object implements Cache<T>
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(Object key,
T value)
This method is used to insert a key value mapping in to the
cache.
|
boolean |
contains(Object key)
This is used to determine whether the specified key exists
with in the cache.
|
T |
fetch(Object key)
This method is used to get the value from the cache that is
mapped to the specified key.
|
boolean |
isEmpty()
This method is used to determine if the cache is empty.
|
T |
take(Object 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 boolean isEmpty()
Cache
public void cache(Object key, T value)
public T take(Object key)
public T fetch(Object key)