com.sun.hk2.component
Class SoftCache<K,V>
java.lang.Object
com.sun.hk2.component.SoftCache<K,V>
public class SoftCache<K,V>
- extends Object
A very primitive cache of at most one entry, that uses both SoftReference(s) to
the key as well as the value it caches. Useful to provide minimal caching
without imposing on heap.
- Author:
- Jeff Trent
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
key
protected SoftReference<K> key
value
protected SoftReference<V> value
SoftCache
public SoftCache()
get
public V get(K k,
Callable<V> callable)
- Returns either the cached value if hasn't been reclaimed by GC. Otherwise invokes
the callable to refresh the cached value, and caching it again in the process.
- Parameters:
key - the key; must be non-nullcallable - the callable in case the cache is empty; must be non-null
- Returns:
- the value (either from cache or populated by the callable as a last resort)
cacheValue
protected V cacheValue(SoftReference<V> value2,
V thisV)
usingCacheValue
protected V usingCacheValue(V thisV)
clear
public void clear()
- Clears the cache
Copyright © 2011 Oracle Corporation. All Rights Reserved.