DATAREDIS-592 - Consider expiry timeout in synchronized RedisCache mode.

We now consider the element expiry when retrieving cache elements with a value loader. Previously, all cache elements that were cached using `@Cacheable(sync=true)` or used `RedisCache.get(Object, Callable)` directly were considered eternal without setting a TTL.

Original Pull Request: #234
This commit is contained in:
Mark Paluch
2017-01-17 12:04:59 +01:00
committed by Christoph Strobl
parent 5d7b057469
commit d3a0c34904
2 changed files with 25 additions and 7 deletions

View File

@@ -248,7 +248,7 @@ public class RedisCacheUnitTests {
verify(connectionMock, times(1)).exec();
}
@Test // DATAREDIS-443
@Test // DATAREDIS-443, DATAREDIS-592
public void getWithCallableShouldReadValueFromCallableAddToCache() {
cache = new RedisCache(CACHE_NAME, NO_PREFIX_BYTES, templateSpy, 0L);
@@ -263,9 +263,29 @@ public class RedisCacheUnitTests {
verify(connectionMock, times(1)).get(eq(KEY_BYTES));
verify(connectionMock, times(1)).multi();
verify(connectionMock, times(1)).set(eq(KEY_BYTES), eq(VALUE_BYTES));
verify(connectionMock, never()).expire(any(byte[].class), anyLong());
verify(connectionMock, times(1)).exec();
}
@Test // DATAREDIS-592
public void getWithCallableShouldReadValueFromCallableAddToCacheWithTtl() {
cache = new RedisCache(CACHE_NAME, NO_PREFIX_BYTES, templateSpy, 100L);
cache.get(KEY, new Callable<Object>() {
@Override
public Object call() throws Exception {
return VALUE;
}
});
verify(connectionMock).get(eq(KEY_BYTES));
verify(connectionMock).multi();
verify(connectionMock).set(eq(KEY_BYTES), eq(VALUE_BYTES));
verify(connectionMock).expire(eq(KEY_BYTES), eq(100L));
verify(connectionMock).exec();
}
@Test // DATAREDIS-443
@SuppressWarnings("unchecked")
public void getWithCallableShouldNotReadValueFromCallableWhenAlreadyPresent() {