This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 93eb32a86 RATIS-2101. Move TermIndex.PRIVATE_CACHE to Util.CACHE 
(#1103)
93eb32a86 is described below

commit 93eb32a8620fdd4e5119592ef32bc50590810c7b
Author: Symious <[email protected]>
AuthorDate: Sat May 25 10:58:20 2024 +0800

    RATIS-2101. Move TermIndex.PRIVATE_CACHE to Util.CACHE (#1103)
---
 .../java/org/apache/ratis/server/protocol/TermIndex.java  | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

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 6a9bd1cfb..a8aa67061 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 @@ 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 +110,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);
     }

Reply via email to