Skip to content

Commit 3961508

Browse files
committed
Return null old value when expired on putX (fixes #26)
1 parent 2c257b9 commit 3961508

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ V put(K key, V value, boolean notifyWriter, boolean onlyIfAbsent) {
10051005
afterRead(prior, now, false);
10061006
}
10071007

1008-
return oldValue;
1008+
return expired ? null : oldValue;
10091009
}
10101010
}
10111011

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ public void putIfAbsent_writerFails(Map<Integer, Integer> map, CacheContext cont
601601
expireAfterWrite = {Expire.DISABLED, Expire.ONE_MINUTE})
602602
public void put_insert(Map<Integer, Integer> map, CacheContext context) {
603603
context.ticker().advance(1, TimeUnit.MINUTES);
604-
map.put(context.firstKey(), context.absentValue());
604+
assertThat(map.put(context.firstKey(), context.absentValue()), is(nullValue()));
605605

606606
long count = context.initialSize();
607607
assertThat(map.size(), is(1));
@@ -616,8 +616,8 @@ public void put_insert(Map<Integer, Integer> map, CacheContext context) {
616616
public void put_replace(Map<Integer, Integer> map, CacheContext context) {
617617
context.ticker().advance(30, TimeUnit.SECONDS);
618618

619-
map.put(context.firstKey(), context.absentValue());
620-
map.put(context.absentKey(), context.absentValue());
619+
assertThat(map.put(context.firstKey(), context.absentValue()), is(not(nullValue())));
620+
assertThat(map.put(context.absentKey(), context.absentValue()), is(nullValue()));
621621
context.consumedNotifications().clear(); // Ignore replacement notification
622622

623623
context.ticker().advance(45, TimeUnit.SECONDS);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public void putIfAbsent(Map<Integer, Integer> map, CacheContext context) {
192192
assertThat(map.putIfAbsent(context.firstKey(), context.absentValue()), is(not(nullValue())));
193193

194194
context.ticker().advance(30, TimeUnit.SECONDS);
195-
map.putIfAbsent(context.lastKey(), context.absentValue());
195+
assertThat(map.putIfAbsent(context.lastKey(), context.absentValue()), is(nullValue()));
196196

197197
long count = context.initialSize() - 1;
198198
assertThat(map.size(), is(2));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void putIfAbsent(Map<Integer, Integer> map, CacheContext context) {
177177
assertThat(map.putIfAbsent(context.firstKey(), context.absentValue()), is(not(nullValue())));
178178

179179
context.ticker().advance(30, TimeUnit.SECONDS);
180-
map.putIfAbsent(context.lastKey(), context.absentValue());
180+
assertThat(map.putIfAbsent(context.lastKey(), context.absentValue()), is(nullValue()));
181181

182182
long count = context.initialSize();
183183
assertThat(map.size(), is(1));

gradle/dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ext {
5757
ehcache2: '2.10.0-10',
5858
ehcache3: '3.0.0.m2',
5959
high_scale_lib: '1.0.6',
60-
infinispan: '8.0.0.CR1',
60+
infinispan: '8.0.0.Final',
6161
jackrabbit: '1.3.4',
6262
jamm: '0.3.1',
6363
java_object_layout: '0.3.2',

0 commit comments

Comments
 (0)