szetszwo commented on PR #1100: URL: https://github.com/apache/ratis/pull/1100#issuecomment-2130219305
@symious , on a second thought, we should keep `EMPTY_ARRAY` since it is in `ratis-server-api`. Also, let's move `PRIVATE_CACHE` inside a class and make it private; see below. Could you file a followup JIRA and submit another pull request? ```java diff --git a/ratis-server-api/src/main/java/org/apache/ratis/server/protocol/TermIndex.java b/ratis-server-api/src/main/java/org/apache/ratis/server/protocol/TermIndex.java index 6a9bd1cfb7..d43ec5d058 100644 --- a/ratis-server-api/src/main/java/org/apache/ratis/server/protocol/TermIndex.java +++ b/ratis-server-api/src/main/java/org/apache/ratis/server/protocol/TermIndex.java @@ -29,11 +29,15 @@ import java.util.concurrent.TimeUnit; /** The term and the log index defined in the Raft consensus algorithm. */ public interface TermIndex extends Comparable<TermIndex> { - /** An LRU Cache for {@link TermIndex} instances */ - Cache<TermIndex, TermIndex> PRIVATE_CACHE = CacheBuilder.newBuilder() - .maximumSize(1 << 16) - .expireAfterAccess(1, TimeUnit.MINUTES) - .build(); + class Util { + /** An LRU Cache for {@link TermIndex} instances */ + private static final Cache<TermIndex, TermIndex> CACHE = CacheBuilder.newBuilder() + .maximumSize(1 << 16) + .expireAfterAccess(1, TimeUnit.MINUTES) + .build(); + } + + TermIndex[] EMPTY_ARRAY = {}; /** @return the term. */ long getTerm(); @@ -107,7 +111,7 @@ public interface TermIndex extends Comparable<TermIndex> { } }; try { - return PRIVATE_CACHE.get(key, () -> key); + return Util.CACHE.get(key, () -> key); } catch (ExecutionException e) { throw new IllegalStateException("Failed to valueOf(" + term + ", " + index + "), key=" + key, e); } ``` -- 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...@ratis.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org