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..a8aa670613 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,14 @@ /** The term and the log index defined in the Raft consensus algorithm. */ public interface TermIndex extends Comparable { - /** An LRU Cache for {@link TermIndex} instances */ - Cache 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 CACHE = CacheBuilder.newBuilder() + .maximumSize(1 << 16) + .expireAfterAccess(1, TimeUnit.MINUTES) + .build(); + } + TermIndex[] EMPTY_ARRAY = {}; /** @return the term. */ long getTerm(); @@ -107,7 +110,7 @@ public String toString() { } }; 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); }