ben-manes commented on a change in pull request #230: URL: https://github.com/apache/solr/pull/230#discussion_r683821705
########## File path: solr/core/src/java/org/apache/solr/search/CaffeineCache.java ########## @@ -190,73 +191,72 @@ public V get(K key) { return cache.getIfPresent(key); } - @Override - public V computeIfAbsent(K key, IOFunction<? super K, ? extends V> mappingFunction) throws IOException { - /* - This block will get deleted before commit, but I'm leaving it in for now in case I have to go back to that apporach + private V computeAsync(K key, IOFunction<? super K, ? extends V> mappingFunction) throws IOException { + // First do a lookup first: optimistic non-locking path. + // The cache does this for us on get(K, Function), but not putIfAbsent + V value = get(key); + if (value != null) { + return value; + } Review comment: Stats gets very funky with a Map, e.g. what stats are recorded for `V replace(k, v)` and `boolean replace(k, old, new)`? In Guava we decided to not record stats for the `asMap()` view and not cherry-pick. That made sense since you could use `Cache.getIfPresent` and prefer a loading `get(k, loader)` over a `putIfAbsent`. In Caffeine, I decided that `compute` was valuable enough to break that practice and record stats. I'd probably lean towards `asMap().get(key)` also recording because it's been a surprise that `getIfPresent` should be used instead, but we have Guava's history to justify keeping as is. Similarly putIfAbsent sounds good, but it gets too confusing about the "correct" stats. Thus the fallback is to tell users to not rely on ours and create their own to get what they deem to be the right metrics. Ours are therefore best effort, but fallible. -- 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