Skip to content

Commit

Permalink
RATIS-2101. Move TermIndex.PRIVATE_CACHE to Util.CACHE
Browse files Browse the repository at this point in the history
  • Loading branch information
symious committed May 25, 2024
1 parent e002587 commit 6f1e231
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@

/** 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();
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 6f1e231

Please sign in to comment.