-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
A zero or negative duration returned from the user's Expiry is treated as an immediate expiration. A negative value was being hashed into a future slot in the second wheel, so it delayed the eviction until that bucket is flushed. This now forces the entry to the current time's bucket so that it gets handled immediately after being added. I suspect that if a Long.MIN_VALUE was used that there might have been an overflow. I didn't investigate that scenario or its impact, and instead focused on more robust handling and tests.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,7 +205,11 @@ public void deschedule(Node<K, V> node) { | |
*/ | ||
@SuppressWarnings("Varifier") | ||
Node<K, V> findBucket(long time) { | ||
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / forbiddenApis
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / forbiddenApis
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / benchmarks (11)
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / benchmarks (11)
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / qodana
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / qodana
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / pmd
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / pmd
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / spotbugs
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / spotbugs
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / Compile (GraalVM)
Check warning on line 207 in caffeine/src/main/java/com/github/benmanes/caffeine/cache/TimerWheel.java GitHub Actions / Compile (GraalVM)
|
||
long duration = time - nanos; | ||
long duration = Math.max(0L, time - nanos); | ||
if (duration <= 0L) { | ||
time = nanos; | ||
} | ||
|
||
int length = wheel.length - 1; | ||
for (int i = 0; i < length; i++) { | ||
if (duration < SPANS[i + 1]) { | ||
|