You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2022/05/16 20:03:04 UTC

[GitHub] [accumulo] dlmarion commented on a diff in pull request #2709: Replaced HashMap in ZooCacheFactory with bounded-size Cache

dlmarion commented on code in PR #2709:
URL: https://github.com/apache/accumulo/pull/2709#discussion_r874109558


##########
core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCacheFactory.java:
##########
@@ -18,18 +18,17 @@
  */
 package org.apache.accumulo.fate.zookeeper;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.accumulo.core.singletons.SingletonManager;
 import org.apache.accumulo.core.singletons.SingletonService;
 
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+
 /**
  * A factory for {@link ZooCache} instances.
  */
 public class ZooCacheFactory {
-  // TODO: make this better - LRU, soft references, ...
-  private static Map<String,ZooCache> instances = new HashMap<>();
+  private static Cache<String,ZooCache> instances = Caffeine.newBuilder().maximumSize(5).build();

Review Comment:
   For Caffeine, specifying a size turns the Cache into an LRU Cache (see https://github.com/ben-manes/caffeine/wiki/Eviction#size-based). As for the number 5, it was arbitrary. I don't know how many ZK's a ClientContext actually communicates with, it's probably 1. But a Cache of 1 didn't make sense. What's your thought?



-- 
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: notifications-unsubscribe@accumulo.apache.org

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