diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java index 778dcde5cd..ede7040cc7 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java @@ -1878,6 +1878,9 @@ public boolean containsValue(Object value) { if (recordStats) { statsCounter().recordMisses(1); } + if (drainStatus() == REQUIRED) { + scheduleDrainBuffers(); + } return null; } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java index 6808544d88..c2585472be 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/BoundedLocalCacheTest.java @@ -543,6 +543,23 @@ public void drain_onRead(Cache cache, CacheContext context) { assertThat(buffer.size(), is(0)); } + @Test(dataProvider = "caches") + @CacheSpec(compute = Compute.SYNC, implementation = Implementation.Caffeine, + population = Population.FULL, maximumSize = Maximum.FULL) + public void drain_onRead_absent(Cache cache, CacheContext context) { + BoundedLocalCache localCache = asBoundedLocalCache(cache); + Buffer> buffer = localCache.readBuffer; + localCache.get(context.firstKey()); + assertThat(buffer.size(), is(1)); + + assertThat(localCache.get(context.absentKey()), is(nullValue())); + assertThat(buffer.size(), is(1)); + + localCache.drainStatus = REQUIRED; + assertThat(localCache.get(context.absentKey()), is(nullValue())); + assertThat(buffer.size(), is(0)); + } + @Test(dataProvider = "caches") @CacheSpec(compute = Compute.SYNC, implementation = Implementation.Caffeine, population = Population.EMPTY, maximumSize = Maximum.FULL)