madrob commented on a change in pull request #230:
URL: https://github.com/apache/solr/pull/230#discussion_r683771913



##########
File path: solr/core/src/java/org/apache/solr/search/CaffeineCache.java
##########
@@ -176,33 +193,92 @@ public V get(K key) {
     return cache.getIfPresent(key);
   }
 
-  @Override
-  public V computeIfAbsent(K key, Function<? super K, ? extends V> 
mappingFunction) {
-    return cache.get(key, k -> {
-      inserts.increment();
-      V value = mappingFunction.apply(k);
-      if (value == null) {
-        return null;
+  private V computeAsync(K key, IOFunction<? super K, ? extends V> 
mappingFunction) throws IOException {
+    CompletableFuture<V> future = new CompletableFuture<>();
+    CompletableFuture<V> result = asyncCache.asMap().putIfAbsent(key, future);
+    if (result != null) {
+      try {
+        // Another thread is already working on this computation, wait for 
them to finish
+        return result.join();

Review comment:
       @ben-manes this code path doesn't seem to record a hit in the cache 
stats for the "happy" case where the result is already completed normally. 
should I be using a different API?




-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to