Skip to content

Commit 7239bb0

Browse files
committed
Schedule on absent lookups if maintenance is required (fixed #420)
1 parent 14e4474 commit 7239bb0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java

+3
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,9 @@ public boolean containsValue(Object value) {
18781878
if (recordStats) {
18791879
statsCounter().recordMisses(1);
18801880
}
1881+
if (drainStatus() == REQUIRED) {
1882+
scheduleDrainBuffers();
1883+
}
18811884
return null;
18821885
}
18831886

caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,23 @@ public void drain_onRead(Cache<Integer, Integer> cache, CacheContext context) {
543543
assertThat(buffer.size(), is(0));
544544
}
545545

546+
@Test(dataProvider = "caches")
547+
@CacheSpec(compute = Compute.SYNC, implementation = Implementation.Caffeine,
548+
population = Population.FULL, maximumSize = Maximum.FULL)
549+
public void drain_onRead_absent(Cache<Integer, Integer> cache, CacheContext context) {
550+
BoundedLocalCache<Integer, Integer> localCache = asBoundedLocalCache(cache);
551+
Buffer<Node<Integer, Integer>> buffer = localCache.readBuffer;
552+
localCache.get(context.firstKey());
553+
assertThat(buffer.size(), is(1));
554+
555+
assertThat(localCache.get(context.absentKey()), is(nullValue()));
556+
assertThat(buffer.size(), is(1));
557+
558+
localCache.drainStatus = REQUIRED;
559+
assertThat(localCache.get(context.absentKey()), is(nullValue()));
560+
assertThat(buffer.size(), is(0));
561+
}
562+
546563
@Test(dataProvider = "caches")
547564
@CacheSpec(compute = Compute.SYNC, implementation = Implementation.Caffeine,
548565
population = Population.EMPTY, maximumSize = Maximum.FULL)

0 commit comments

Comments
 (0)