public abstract class ReferenceCache<K,V> extends ReferenceMap<K,V>
ReferenceMap
to support lazy loading values by overriding
create(Object)
.ReferenceMap.Strategy
Constructor and Description |
---|
ReferenceCache()
Equivalent to
new ReferenceCache(STRONG, STRONG) . |
ReferenceCache(ReferenceType keyReferenceType,
ReferenceType valueReferenceType) |
Modifier and Type | Method and Description |
---|---|
protected void |
cancel()
Cancels the current
create(Object) . |
protected abstract V |
create(K key)
Override to lazy load values.
|
V |
get(Object key) |
static <K,V> ReferenceCache<K,V> |
of(ReferenceType keyReferenceType,
ReferenceType valueReferenceType,
Function<? super K,? extends V> function)
Returns a
ReferenceCache delegating to the specified function . |
clear, containsKey, containsValue, entrySet, getPutStrategy, isEmpty, keySet, put, putAll, putIfAbsent, putIfAbsentStrategy, putStrategy, remove, remove, replace, replace, replaceStrategy, size, values
public ReferenceCache(ReferenceType keyReferenceType, ReferenceType valueReferenceType)
public ReferenceCache()
new ReferenceCache(STRONG, STRONG)
.protected abstract V create(K key)
ReferenceMap.put(Object, Object)
. Invoked by getter if value isn't already cached.
Must not return null
. This method will not be called again until
the garbage collector reclaims the returned value.key
- the keypublic V get(Object key)
If this map does not contain an entry for the given key and create(Object)
has been overridden, this method will create a new
value, put it in the map, and return it.
get
in interface Map<K,V>
get
in class ReferenceMap<K,V>
key
- the keyNullPointerException
- if create(Object)
returns null.CancellationException
- if the creation is
cancelled. See cancel()
.protected void cancel()
create(Object)
. Throws CancellationException
to all clients currently
blocked on get(Object)
.public static <K,V> ReferenceCache<K,V> of(ReferenceType keyReferenceType, ReferenceType valueReferenceType, Function<? super K,? extends V> function)
ReferenceCache
delegating to the specified function
. The specified function must not return null
.K
- type of keyV
- type of valuefunction
- functionkeyReferenceType
- key reference typevalueReferenceType
- value reference typeCopyright © 2000–2020 Apache Software Foundation. All rights reserved.