Skip to content

Commit

Permalink
add Cache#wrap() method to fix a dataflow problem
Browse files Browse the repository at this point in the history
  • Loading branch information
burdoto committed Jul 16, 2024
1 parent c6b4eb3 commit fc00a3f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/main/java/org/comroid/api/map/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,22 @@ public boolean containsKey(Object key0) {
return map.get(key).get() != null;
}

@Override
public @Nullable V get(Object key0) {
K key = uncheckedCast(key0);
public Optional<V> wrap(K key) {
var ref = map.get(key);
V value = null;
V value = null;
if (ref != null) {
value = ref.get();
ref.enqueue();
}
if (value == null)
value = compute(key, (k, v) -> refresh.apply(k).orElse(null));
return Optional.ofNullable(value);
}

@Override
public @Nullable V get(Object key0) {
K key = uncheckedCast(key0);
V value = wrap(key).orElse(null);
if (value != null) {
ref = referenceCtor.apply(value, queue);
var ref = referenceCtor.apply(value, queue);
map.put(key, ref);
}
return value;
Expand Down

0 comments on commit fc00a3f

Please sign in to comment.