K - type of cache keyV - type of cached valuepublic class SoftCache<K,V> extends Object
soft reference.| Modifier and Type | Class and Description |
|---|---|
static interface |
SoftCache.Finder<K,V>
Implementations of this interface may be used to provide values not in the cache yet.
|
private static class |
SoftCache.NullFinder<K,V>
Default implementation which does not find anything.
|
| Modifier and Type | Field and Description |
|---|---|
private Map<K,SoftReference<V>> |
data
Holds the cached data.
|
private SoftCache.Finder<K,V> |
finder
Try to finds values if a key not present yet in cache.
|
| Constructor and Description |
|---|
SoftCache() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(K key,
V value)
Add a value to the cache.
|
void |
finder(SoftCache.Finder<K,V> f)
Set the finder for this cache.
|
V |
get(K key)
Get a value from the cache.
|
void |
remove(K key)
Removes value from cache.
|
private final Map<K,SoftReference<V>> data
private SoftCache.Finder<K,V> finder
public V get(K key)
If key not present yet, then the finder is asked. If no finder set a default finder is used which does not find anything.
key - must not be nullnullpublic void add(K key, V value)
key - must not be nullvalue - must not be nullpublic void remove(K key)
key - must not be nullpublic void finder(SoftCache.Finder<K,V> f)
f - must not be nullCopyright © 2014 Sven Strittmatter. All Rights Reserved.