ben-manes commented on a change in pull request #230:
URL: https://github.com/apache/solr/pull/230#discussion_r683832835



##########
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:
       I think stats on an async cache, especially with the `asMap()` view, is 
confusing. I don't know if I got it instrumented right. It tries to be good 
enough but either requires a deeper review to fix holes, or custom stats to 
match your desired reporting.




-- 
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