From 39615086a310c9cf2c58b1ac70fc7c3fb093b4ff Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Wed, 2 Sep 2015 17:11:01 -0700 Subject: [PATCH] Return null old value when expired on putX (fixes #26) --- .../github/benmanes/caffeine/cache/BoundedLocalCache.java | 2 +- .../com/github/benmanes/caffeine/cache/ExpirationTest.java | 6 +++--- .../benmanes/caffeine/cache/ExpireAfterAccessTest.java | 2 +- .../benmanes/caffeine/cache/ExpireAfterWriteTest.java | 2 +- gradle/dependencies.gradle | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) 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 b03cf56811..5bab0c123f 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 @@ -1005,7 +1005,7 @@ V put(K key, V value, boolean notifyWriter, boolean onlyIfAbsent) { afterRead(prior, now, false); } - return oldValue; + return expired ? null : oldValue; } } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpirationTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpirationTest.java index 277a27e622..80933ece6d 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpirationTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpirationTest.java @@ -601,7 +601,7 @@ public void putIfAbsent_writerFails(Map map, CacheContext cont expireAfterWrite = {Expire.DISABLED, Expire.ONE_MINUTE}) public void put_insert(Map map, CacheContext context) { context.ticker().advance(1, TimeUnit.MINUTES); - map.put(context.firstKey(), context.absentValue()); + assertThat(map.put(context.firstKey(), context.absentValue()), is(nullValue())); long count = context.initialSize(); assertThat(map.size(), is(1)); @@ -616,8 +616,8 @@ public void put_insert(Map map, CacheContext context) { public void put_replace(Map map, CacheContext context) { context.ticker().advance(30, TimeUnit.SECONDS); - map.put(context.firstKey(), context.absentValue()); - map.put(context.absentKey(), context.absentValue()); + assertThat(map.put(context.firstKey(), context.absentValue()), is(not(nullValue()))); + assertThat(map.put(context.absentKey(), context.absentValue()), is(nullValue())); context.consumedNotifications().clear(); // Ignore replacement notification context.ticker().advance(45, TimeUnit.SECONDS); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterAccessTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterAccessTest.java index 20df8c8e19..d7826f7541 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterAccessTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterAccessTest.java @@ -192,7 +192,7 @@ public void putIfAbsent(Map map, CacheContext context) { assertThat(map.putIfAbsent(context.firstKey(), context.absentValue()), is(not(nullValue()))); context.ticker().advance(30, TimeUnit.SECONDS); - map.putIfAbsent(context.lastKey(), context.absentValue()); + assertThat(map.putIfAbsent(context.lastKey(), context.absentValue()), is(nullValue())); long count = context.initialSize() - 1; assertThat(map.size(), is(2)); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterWriteTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterWriteTest.java index e54eea7fe6..2308067872 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterWriteTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ExpireAfterWriteTest.java @@ -177,7 +177,7 @@ public void putIfAbsent(Map map, CacheContext context) { assertThat(map.putIfAbsent(context.firstKey(), context.absentValue()), is(not(nullValue()))); context.ticker().advance(30, TimeUnit.SECONDS); - map.putIfAbsent(context.lastKey(), context.absentValue()); + assertThat(map.putIfAbsent(context.lastKey(), context.absentValue()), is(nullValue())); long count = context.initialSize(); assertThat(map.size(), is(1)); diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index aadbdbeaaf..1c47b75d1f 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -57,7 +57,7 @@ ext { ehcache2: '2.10.0-10', ehcache3: '3.0.0.m2', high_scale_lib: '1.0.6', - infinispan: '8.0.0.CR1', + infinispan: '8.0.0.Final', jackrabbit: '1.3.4', jamm: '0.3.1', java_object_layout: '0.3.2',