|
|
@@ -115,6 +115,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
|
|
|
@Override
|
|
|
public V get(Object key) {
|
|
|
synchronized(this) {
|
|
|
+ map.release();
|
|
|
V result = map.getValue(key);
|
|
|
if (null != result) {
|
|
|
list.hold(result);
|
|
|
@@ -125,6 +126,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
|
|
|
|
|
|
public V get(K key, Supplier<V> supplier) {
|
|
|
synchronized(this) {
|
|
|
+ map.release();
|
|
|
V result = map.getValue(key);
|
|
|
if (null == result) {
|
|
|
map.putValue(key, result = supplier.get());
|
|
|
@@ -242,7 +244,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
private static <TK> TK asKey(Reference<?> ref) {
|
|
|
- return (ref != null) ? ((KRef<TK,?>)ref).key : null;
|
|
|
+ return ((KRef<TK,?>)ref).key;
|
|
|
}
|
|
|
|
|
|
private static class KRef<K,V> extends SoftReference<V> {
|
|
|
@@ -288,7 +290,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected boolean removeEldestEntry(Entry<K, TRef<K,V>> eldest) {
|
|
|
+ protected boolean removeEldestEntry(Map.Entry<K, TRef<K,V>> eldest) {
|
|
|
return this.size() > maxsize || eldest.getValue().time.isAfter(Instant.now());
|
|
|
}
|
|
|
|
|
|
@@ -299,7 +301,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
|
|
|
while ( null != (ref = queue.poll()) ) { remove( asKey(ref) ); }
|
|
|
|
|
|
Instant now = Instant.now();
|
|
|
- Iterator<Entry<K, TRef<K, V>>> iterator = entrySet().iterator();
|
|
|
+ Iterator<Map.Entry<K, TRef<K, V>>> iterator = entrySet().iterator();
|
|
|
while(iterator.hasNext()) {
|
|
|
if(iterator.next().getValue().time.isBefore(now)) {
|
|
|
break;
|
|
|
@@ -341,7 +343,7 @@ public class Cache<K,V> extends AbstractMap<K,V> {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected boolean removeEldestEntry(Entry<K, KRef<K,V>> eldest) {
|
|
|
+ protected boolean removeEldestEntry(Map.Entry<K, KRef<K,V>> eldest) {
|
|
|
return this.size() > maxsize;
|
|
|
}
|
|
|
|