Akshat-Jain commented on code in PR #17212:
URL: https://github.com/apache/druid/pull/17212#discussion_r1797145595
##########
extensions-core/lookups-cached-single/src/main/java/org/apache/druid/server/lookup/LoadingLookup.java:
##########
@@ -74,14 +75,22 @@ public String apply(@Nullable final String key)
}
final String presentVal;
- try {
- presentVal = loadingCache.get(keyEquivalent, new
ApplyCallable(keyEquivalent));
+ presentVal = this.loadingCache.getIfPresent(keyEquivalent);
+ if (presentVal != null) {
return NullHandling.emptyToNullIfNeeded(presentVal);
}
- catch (ExecutionException e) {
- LOGGER.debug("value not found for key [%s]", key);
+
+ String val = this.dataFetcher.fetch(keyEquivalent);
+ if (val == null) {
return null;
}
+
+ Map<String, String> map = new HashMap<>();
+ map.put(keyEquivalent, val);
+
+ this.loadingCache.putAll(map);
+
+ return NullHandling.emptyToNullIfNeeded(val);
Review Comment:
> The old code, if I get right, was just getting data from the loading cache
and if it just returns the value from there whether it exists or not, the cache
is never updated
In the old code, we are loading the value into the `loadingCache` if needed
by passing `new ApplyCallable(keyEquivalent)` as the `valueLoader` parameter in
this line:
```java
presentVal = loadingCache.get(keyEquivalent, new
ApplyCallable(keyEquivalent))
```
I also did some basic testing locally to confirm this, and I could see the
cache being updated with the `keyEquivalent` value if it's not present in the
cache. So I think this part of the PR can be reverted back to the original
code, as it's functionally equivalent.
Please let me know if I'm missing anything though. Thanks! :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]