Skip to content

Commit

Permalink
add double check for synchronization for caching with sync=true
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Jun 18, 2024
1 parent 180c353 commit 0753898
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,17 @@ public Object getNativeCache() {
@SuppressWarnings({"NullableProblems"})
public <T> T get(Object key, Callable<T> valueLoader) {
Key dbKey = getKey(key);
Record record;
synchronized (this) {
record = client.get(null, dbKey);
if (record == null) {
T value = callValueLoader(valueLoader, key);
if (Objects.nonNull(value)) {
put(key, value);
Record record = client.get(null, dbKey);
if (record == null && valueLoader != null) {
synchronized (this) {
record = client.get(null, dbKey);
if (record == null) {
T value = callValueLoader(valueLoader, key);
if (Objects.nonNull(value)) {
put(key, value);
}
return value;
}
return value;
}
}
if (record.getValue(VALUE) != null) {
Expand Down

0 comments on commit 0753898

Please sign in to comment.