Skip to content

Commit

Permalink
CLDR-7646 fix for TestCache issue
Browse files Browse the repository at this point in the history
- was initializing the cache incorrectly
  • Loading branch information
srl295 committed Jan 21, 2024
1 parent b8d4472 commit 60dff10
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tools/cldr-code/src/main/java/org/unicode/cldr/test/TestCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
Expand Down Expand Up @@ -95,12 +98,19 @@ public List<CheckStatus> getPossibleProblems() {
* evaluate why the fallback 12 for CLDR_TESTCACHE_SIZE is appropriate or too small. Consider not
* using maximumSize() at all, depending on softValues() instead to garbage collect only when needed.
*/
private Cache<CheckCLDR.Options, TestResultBundle> testResultCache =
private LoadingCache<CheckCLDR.Options, TestResultBundle> testResultCache =
CacheBuilder.newBuilder()
.maximumSize(CLDRConfig.getInstance().getProperty("CLDR_TESTCACHE_SIZE", 12))
.concurrencyLevel(1)
.softValues()
.build();
.build(
new CacheLoader<CheckCLDR.Options, TestResultBundle>() {

@Override
public TestResultBundle load(Options key) throws Exception {
return new TestResultBundle(key);
}
}
);

private final Factory factory;

Expand All @@ -110,7 +120,7 @@ public List<CheckStatus> getPossibleProblems() {
public TestResultBundle getBundle(final CheckCLDR.Options options) {
TestResultBundle b;
try {
b = testResultCache.get(options, () -> new TestResultBundle(options));
b = testResultCache.get(options);
} catch (ExecutionException e) {
logger.log(Level.SEVERE, e, () -> "Failed to load " + options);
throw new RuntimeException(e);
Expand Down

0 comments on commit 60dff10

Please sign in to comment.