Skip to content

Commit 8a52af6

Browse files
committed
Update eviction threshold to nanoseconds and adjust related logic in ConfigFetcher
1 parent 285cbd2 commit 8a52af6

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/main/java/com/configcat/ConfigFetcher.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ class ConfigFetcher implements Closeable {
1313

1414
private static final long RETRY_DELAY_MS = 50;
1515

16-
private static final long EVICT_ALL_THRESHOLD_MS = 30000;
16+
private static final long EVICT_ALL_THRESHOLD_NS = 30_000_000_000L; // 30 seconds in nanoseconds
1717

1818
private final AtomicBoolean isClosed = new AtomicBoolean(false);
1919
private final ConfigCatLogger logger;
2020
private final OkHttpClient httpClient;
2121
private final String mode;
2222

23-
private long lastEvictAllTimestamp = 0;
23+
private long lastEvictAllTimestamp = Long.MIN_VALUE;
2424

2525
private final String sdkKey;
2626
private final boolean urlIsCustom;
@@ -182,8 +182,8 @@ private CompletableFuture<FetchResponse> fetchWithRetryAsync(final String eTag)
182182
return this.getResponseAsync(eTag).thenComposeAsync(response -> {
183183
if (response.shouldRetry()) {
184184
try {
185-
long now = System.currentTimeMillis();
186-
if (lastEvictAllTimestamp == 0 || (now - lastEvictAllTimestamp) >= EVICT_ALL_THRESHOLD_MS) {
185+
long now = System.nanoTime();
186+
if (lastEvictAllTimestamp == Long.MIN_VALUE || (now - lastEvictAllTimestamp) >= EVICT_ALL_THRESHOLD_NS) {
187187
this.httpClient.connectionPool().evictAll();
188188
lastEvictAllTimestamp = now;
189189
}

src/test/java/com/configcat/ConfigFetcherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public void evictAllThrottledWithin30Seconds() throws Exception {
430430
"", this.server.url("/").toString(), false, PollingModes.manualPoll().getPollingIdentifier());
431431

432432
// First fetch: evictAll should be called, timestamp set
433-
assertEquals(0, getLastEvictAllTimestampWithReflection(fetcher));
433+
assertEquals(Long.MIN_VALUE, getLastEvictAllTimestampWithReflection(fetcher));
434434
FetchResponse response1 = fetcher.fetchAsync(null).get();
435435
assertTrue(response1.isFetched());
436436
long firstTimestamp = getLastEvictAllTimestampWithReflection(fetcher);

0 commit comments

Comments
 (0)