diff --git a/docs/src/main/asciidoc/cache-redis-reference.adoc b/docs/src/main/asciidoc/cache-redis-reference.adoc index cec715482b675..917c8f8cf853f 100644 --- a/docs/src/main/asciidoc/cache-redis-reference.adoc +++ b/docs/src/main/asciidoc/cache-redis-reference.adoc @@ -101,13 +101,13 @@ You can also configure the time to live of the cached entries: [source, properties] ---- # Default configuration -quarkus.cache.redis.ttl=10s +quarkus.cache.redis.expire-after-write=10s # Configuration for `expensiveResourceCache` -quarkus.cache.redis.expensiveResourceCache.ttl=1h +quarkus.cache.redis.expensiveResourceCache.expire-after-write=1h ---- -If the `ttl` is not configured, the entry won't be evicted. +If the `expire-after-write` is not configured, the entry won't be evicted. You would need to invalidate the values using the `@CacheInvalidateAll` or `@CacheInvalidate` annotations. The following table lists the supported properties: diff --git a/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheBuildRecorder.java b/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheBuildRecorder.java index d4c95091d5680..a55f128de6fbf 100644 --- a/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheBuildRecorder.java +++ b/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheBuildRecorder.java @@ -51,7 +51,7 @@ public CacheManager get() { if (LOGGER.isDebugEnabled()) { LOGGER.debugf( "Building Redis cache [%s] with [ttl=%s], [prefix=%s], [classOfItems=%s]", - cacheInfo.name, cacheInfo.ttl, cacheInfo.prefix, + cacheInfo.name, cacheInfo.expireAfterAccess, cacheInfo.prefix, cacheInfo.valueType); } diff --git a/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheImpl.java b/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheImpl.java index a3624e424026c..79ea2d1f47f1f 100644 --- a/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheImpl.java +++ b/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheImpl.java @@ -1,6 +1,7 @@ package io.quarkus.cache.redis.runtime; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.List; import java.util.Map; import java.util.Objects; @@ -32,7 +33,7 @@ * This class is an internal Quarkus cache implementation using Redis. * Do not use it explicitly from your Quarkus application. */ -public class RedisCacheImpl extends AbstractCache implements RedisCache { +public class RedisCacheImpl extends AbstractCache implements RedisCache { private static final Map> PRIMITIVE_TO_CLASS_MAPPING = Map.of( "int", Integer.class, @@ -48,8 +49,8 @@ public class RedisCacheImpl extends AbstractCache implements RedisCache { private final Redis redis; private final RedisCacheInfo cacheInfo; - private final Class classOfValue; - private final Class classOfKey; + private final Class classOfValue; + private final Class classOfKey; private final Marshaller marshaller; @@ -70,21 +71,20 @@ private static Redis determineRedisClient(Optional redisClientName) { } } - @SuppressWarnings("unchecked") public RedisCacheImpl(RedisCacheInfo cacheInfo, Vertx vertx, Redis redis, Supplier blockingAllowedSupplier) { this.vertx = vertx; this.cacheInfo = cacheInfo; this.blockingAllowedSupplier = blockingAllowedSupplier; try { - this.classOfKey = (Class) loadClass(this.cacheInfo.keyType); + this.classOfKey = loadClass(this.cacheInfo.keyType); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Unable to load the class " + this.cacheInfo.keyType, e); } if (this.cacheInfo.valueType != null) { try { - this.classOfValue = (Class) loadClass(this.cacheInfo.valueType); + this.classOfValue = loadClass(this.cacheInfo.valueType); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Unable to load the class " + this.cacheInfo.valueType, e); } @@ -290,7 +290,7 @@ public Uni apply(List listOfKeys) { var req = Request.cmd(Command.DEL); boolean hasAtLEastOneMatch = false; for (String key : listOfKeys) { - K userKey = computeUserKey(key); + Object userKey = computeUserKey(key); if (predicate.test(userKey)) { hasAtLEastOneMatch = true; req.arg(marshaller.encode(key)); @@ -315,7 +315,7 @@ String computeActualKey(String key) { } } - K computeUserKey(String key) { + Object computeUserKey(String key) { String prefix = cacheInfo.prefix != null ? cacheInfo.prefix : "cache:" + getName(); if (!key.startsWith(prefix + ":")) { return null; // Not a key handle by the cache. @@ -354,21 +354,32 @@ private Uni watch(RedisConnection connection, byte[] keyToWatch) { .replaceWithVoid(); } - private static Uni doGet(RedisConnection connection1, byte[] encodedKey1, Class clazz, + private Uni doGet(RedisConnection connection, byte[] encoded, Class clazz, Marshaller marshaller) { - return connection1.send(Request.cmd(Command.GET).arg(encodedKey1)) - .map(new Function() { - @Override - public X apply(Response r) { - return marshaller.decode(clazz, r); - } - }); + if (cacheInfo.expireAfterAccess.isPresent()) { + Duration duration = cacheInfo.expireAfterAccess.get(); + return connection.send(Request.cmd(Command.GETEX).arg(encoded).arg("EX").arg(duration.toSeconds())) + .map(new Function() { + @Override + public X apply(Response r) { + return marshaller.decode(clazz, r); + } + }); + } else { + return connection.send(Request.cmd(Command.GET).arg(encoded)) + .map(new Function() { + @Override + public X apply(Response r) { + return marshaller.decode(clazz, r); + } + }); + } } private Uni set(RedisConnection connection, byte[] key, byte[] value) { Request request = Request.cmd(Command.SET).arg(key).arg(value); - if (cacheInfo.ttl.isPresent()) { - request = request.arg("EX").arg(cacheInfo.ttl.get().toSeconds()); + if (cacheInfo.expireAfterWrite.isPresent()) { + request = request.arg("EX").arg(cacheInfo.expireAfterWrite.get().toSeconds()); } return connection.send(request).replaceWithVoid(); } @@ -403,7 +414,7 @@ public V get() { } } - private static class GetFromConnectionSupplier implements Supplier> { + private class GetFromConnectionSupplier implements Supplier> { private final RedisConnection connection; private final Class clazz; private final byte[] encodedKey; diff --git a/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheInfo.java b/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheInfo.java index 54bc0e0062559..b6408ab061e4e 100644 --- a/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheInfo.java +++ b/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheInfo.java @@ -13,7 +13,12 @@ public class RedisCacheInfo { /** * The default time to live of the item stored in the cache */ - public Optional ttl = Optional.empty(); + public Optional expireAfterAccess = Optional.empty(); + + /** + * The default time to live to add to the item once read + */ + public Optional expireAfterWrite = Optional.empty(); /** * the key prefix allowing to identify the keys belonging to the cache. diff --git a/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheInfoBuilder.java b/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheInfoBuilder.java index 84467b2e80c0c..80113eee560ba 100644 --- a/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheInfoBuilder.java +++ b/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheInfoBuilder.java @@ -23,10 +23,23 @@ public static Set build(Set cacheNames, RedisCachesBuild RedisCacheRuntimeConfig defaultRuntimeConfig = runtimeConfig.defaultConfig; RedisCacheRuntimeConfig namedRuntimeConfig = runtimeConfig.cachesConfig.get(cacheInfo.name); + if (namedRuntimeConfig != null && namedRuntimeConfig.expireAfterAccess.isPresent()) { + cacheInfo.expireAfterAccess = namedRuntimeConfig.expireAfterAccess; + } else if (defaultRuntimeConfig.expireAfterAccess.isPresent()) { + cacheInfo.expireAfterAccess = defaultRuntimeConfig.expireAfterAccess; + } + + if (namedRuntimeConfig != null && namedRuntimeConfig.expireAfterWrite.isPresent()) { + cacheInfo.expireAfterWrite = namedRuntimeConfig.expireAfterWrite; + } else if (defaultRuntimeConfig.expireAfterAccess.isPresent()) { + cacheInfo.expireAfterWrite = defaultRuntimeConfig.expireAfterWrite; + } + + // Handle the deprecated TTL if (namedRuntimeConfig != null && namedRuntimeConfig.ttl.isPresent()) { - cacheInfo.ttl = namedRuntimeConfig.ttl; + cacheInfo.expireAfterWrite = namedRuntimeConfig.ttl; } else if (defaultRuntimeConfig.ttl.isPresent()) { - cacheInfo.ttl = defaultRuntimeConfig.ttl; + cacheInfo.expireAfterWrite = defaultRuntimeConfig.ttl; } if (namedRuntimeConfig != null && namedRuntimeConfig.prefix.isPresent()) { diff --git a/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheRuntimeConfig.java b/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheRuntimeConfig.java index 3171817e06588..e08c9a48b4523 100644 --- a/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheRuntimeConfig.java +++ b/extensions/redis-cache/runtime/src/main/java/io/quarkus/cache/redis/runtime/RedisCacheRuntimeConfig.java @@ -9,11 +9,28 @@ @ConfigGroup public class RedisCacheRuntimeConfig { /** - * The default time to live of the item stored in the cache + * The default time to live of the item stored in the cache. + * + * @deprecated Use {@link #expireAfterWrite} instead. */ @ConfigItem + @Deprecated public Optional ttl; + /** + * Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after + * the entry's creation, or the most recent replacement of its value. + */ + @ConfigItem + Optional expireAfterWrite; + + /** + * Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after + * the last access of its value. + */ + @ConfigItem + Optional expireAfterAccess; + /** * the key prefix allowing to identify the keys belonging to the cache. * If not set, use "cache:$cache-name" diff --git a/extensions/redis-cache/runtime/src/test/java/io/quarkus/cache/redis/runtime/RedisCacheImplTest.java b/extensions/redis-cache/runtime/src/test/java/io/quarkus/cache/redis/runtime/RedisCacheImplTest.java index ed5ad172528d2..c69a50ff13796 100644 --- a/extensions/redis-cache/runtime/src/test/java/io/quarkus/cache/redis/runtime/RedisCacheImplTest.java +++ b/extensions/redis-cache/runtime/src/test/java/io/quarkus/cache/redis/runtime/RedisCacheImplTest.java @@ -3,10 +3,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.awaitility.Awaitility.await; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.time.Duration; -import java.util.*; +import java.util.HashSet; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; import java.util.function.Supplier; import org.junit.jupiter.api.AfterEach; @@ -34,22 +38,22 @@ public void testPutInTheCache() { RedisCacheInfo info = new RedisCacheInfo(); info.name = "foo"; info.valueType = String.class.getName(); - info.ttl = Optional.of(Duration.ofSeconds(2)); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(2)); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); assertThat(cache.get(k, s -> "hello").await().indefinitely()).isEqualTo("hello"); var r = redis.send(Request.cmd(Command.GET).arg("cache:foo:" + k)).await().indefinitely(); assertThat(r).isNotNull(); } @Test - public void testPutInTheCacheWithOptimisitcLocking() { + public void testPutInTheCacheWithOptimisticLocking() { String k = UUID.randomUUID().toString(); RedisCacheInfo info = new RedisCacheInfo(); info.name = "foo"; info.valueType = String.class.getName(); - info.ttl = Optional.of(Duration.ofSeconds(2)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(2)); info.useOptimisticLocking = true; - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); assertThat(cache.get(k, s -> "hello").await().indefinitely()).isEqualTo("hello"); var r = redis.send(Request.cmd(Command.GET).arg("cache:foo:" + k)).await().indefinitely(); assertThat(r).isNotNull(); @@ -60,20 +64,41 @@ public void testPutAndWaitForInvalidation() { String k = UUID.randomUUID().toString(); RedisCacheInfo info = new RedisCacheInfo(); info.valueType = String.class.getName(); - info.ttl = Optional.of(Duration.ofSeconds(1)); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(1)); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); assertThat(cache.get(k, s -> "hello").await().indefinitely()).isEqualTo("hello"); var x = cache.get(k, String::toUpperCase).await().indefinitely(); assertEquals(x, "hello"); await().until(() -> cache.getOrNull(k, String.class).await().indefinitely() == null); } + @Test + public void testExpireAfterReadAndWrite() throws InterruptedException { + String k = UUID.randomUUID().toString(); + RedisCacheInfo info = new RedisCacheInfo(); + info.name = "foo"; + info.valueType = String.class.getName(); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(1)); + info.expireAfterAccess = Optional.of(Duration.ofSeconds(1)); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); + assertThat(cache.get(k, s -> "hello").await().indefinitely()).isEqualTo("hello"); + var x = cache.get(k, String::toUpperCase).await().indefinitely(); + assertEquals(x, "hello"); + for (int i = 0; i < 3; i++) { + x = cache.get(k, String::toUpperCase).await().indefinitely(); + assertEquals(x, "hello"); + Thread.sleep(500); + } + await().until(() -> redis.send(Request.cmd(Command.GET).arg("cache:foo:" + k)).await().indefinitely() == null); + await().until(() -> cache.getOrNull(k, String.class).await().indefinitely() == null); + } + @Test public void testManualInvalidation() { RedisCacheInfo info = new RedisCacheInfo(); info.valueType = String.class.getName(); - info.ttl = Optional.of(Duration.ofSeconds(10)); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(10)); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); cache.get("foo", s -> "hello").await().indefinitely(); var x = cache.get("foo", String::toUpperCase).await().indefinitely(); assertEquals(x, "hello"); @@ -114,9 +139,9 @@ public int hashCode() { @Test public void testGetOrNull() { RedisCacheInfo info = new RedisCacheInfo(); - info.ttl = Optional.of(Duration.ofSeconds(10)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(10)); info.valueType = Person.class.getName(); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); Person person = cache.getOrNull("foo", Person.class).await().indefinitely(); assertThat(person).isNull(); assertThatTheKeyDoesNotExist("cache:foo"); @@ -134,9 +159,9 @@ public void testGetOrNull() { @Test public void testGetOrDefault() { RedisCacheInfo info = new RedisCacheInfo(); - info.ttl = Optional.of(Duration.ofSeconds(10)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(10)); info.valueType = Person.class.getName(); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); Person person = cache.getOrDefault("foo", new Person("bar", "BAR")).await().indefinitely(); assertThat(person).isNotNull() .satisfies(p -> { @@ -160,9 +185,9 @@ public void testGetOrDefault() { @Test public void testCacheNullValue() { RedisCacheInfo info = new RedisCacheInfo(); - info.ttl = Optional.of(Duration.ofSeconds(10)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(10)); info.valueType = Person.class.getName(); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); // with custom key double key = 122334545.0; @@ -174,11 +199,11 @@ public void testCacheNullValue() { @Test public void testExceptionInValueLoader() { RedisCacheInfo info = new RedisCacheInfo(); - info.ttl = Optional.of(Duration.ofSeconds(10)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(10)); info.valueType = Person.class.getName(); info.keyType = Double.class.getName(); info.name = "foo"; - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); // with custom key and exception Double key = 122334545.0; @@ -197,10 +222,10 @@ public void testExceptionInValueLoader() { @Test public void testPutShouldPopulateCache() { RedisCacheInfo info = new RedisCacheInfo(); - info.ttl = Optional.of(Duration.ofSeconds(10)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(10)); info.valueType = Person.class.getName(); info.keyType = Integer.class.getName(); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); cache.put(1, new Person("luke", "skywalker")).await().indefinitely(); assertThat(cache.get(1, x -> new Person("1", "1")).await().indefinitely()).isEqualTo(new Person("luke", "skywalker")); @@ -213,11 +238,11 @@ public void testPutShouldPopulateCache() { @Test public void testPutShouldPopulateCacheWithOptimisticLocking() { RedisCacheInfo info = new RedisCacheInfo(); - info.ttl = Optional.of(Duration.ofSeconds(10)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(10)); info.valueType = Person.class.getName(); info.keyType = Integer.class.getName(); info.useOptimisticLocking = true; - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); cache.put(1, new Person("luke", "skywalker")).await().indefinitely(); assertThat(cache.get(1, x -> new Person("1", "1")).await().indefinitely()).isEqualTo(new Person("luke", "skywalker")); @@ -233,8 +258,8 @@ public void testThatConnectionsAreRecycled() { RedisCacheInfo info = new RedisCacheInfo(); info.name = "foo"; info.valueType = String.class.getName(); - info.ttl = Optional.of(Duration.ofSeconds(1)); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(1)); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); for (int i = 0; i < 1000; i++) { String val = "hello-" + i; @@ -258,9 +283,9 @@ public void testThatConnectionsAreRecycledWithOptimisticLocking() { RedisCacheInfo info = new RedisCacheInfo(); info.name = "foo"; info.valueType = String.class.getName(); - info.ttl = Optional.of(Duration.ofSeconds(1)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(1)); info.useOptimisticLocking = true; - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); for (int i = 0; i < 1000; i++) { String val = "hello-" + i; @@ -282,8 +307,8 @@ public void testThatConnectionsAreRecycledWithOptimisticLocking() { void testWithMissingDefaultType() { RedisCacheInfo info = new RedisCacheInfo(); info.name = "missing-default-cache"; - info.ttl = Optional.of(Duration.ofSeconds(10)); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(10)); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); assertThatThrownBy(() -> cache.get("test", x -> "value").await().indefinitely()) .isInstanceOf(UnsupportedOperationException.class); @@ -304,9 +329,9 @@ void testWithMissingDefaultType() { void testAsyncGetWithDefaultType() { RedisCacheInfo info = new RedisCacheInfo(); info.name = "star-wars"; - info.ttl = Optional.of(Duration.ofSeconds(2)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(2)); info.valueType = Person.class.getName(); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); assertThat(cache .getAsync("test", @@ -334,10 +359,10 @@ void testAsyncGetWithDefaultType() { void testAsyncGetWithDefaultTypeWithOptimisticLocking() { RedisCacheInfo info = new RedisCacheInfo(); info.name = "star-wars"; - info.ttl = Optional.of(Duration.ofSeconds(2)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(2)); info.valueType = Person.class.getName(); info.useOptimisticLocking = true; - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); assertThat(cache .getAsync("test", @@ -365,9 +390,9 @@ void testAsyncGetWithDefaultTypeWithOptimisticLocking() { void testPut() { RedisCacheInfo info = new RedisCacheInfo(); info.name = "put"; - info.ttl = Optional.of(Duration.ofSeconds(2)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(2)); info.valueType = Person.class.getName(); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); Person luke = new Person("luke", "skywalker"); Person leia = new Person("leia", "organa"); @@ -384,9 +409,9 @@ void testPut() { void testPutWithSupplier() { RedisCacheInfo info = new RedisCacheInfo(); info.name = "put"; - info.ttl = Optional.of(Duration.ofSeconds(2)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(2)); info.valueType = Person.class.getName(); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); Person luke = new Person("luke", "skywalker"); Person leia = new Person("leia", "organa"); @@ -403,10 +428,10 @@ void testPutWithSupplier() { void testInitializationWithAnUnknownClass() { RedisCacheInfo info = new RedisCacheInfo(); info.name = "put"; - info.ttl = Optional.of(Duration.ofSeconds(2)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(2)); info.valueType = Person.class.getPackage().getName() + ".Missing"; - assertThatThrownBy(() -> new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED)) + assertThatThrownBy(() -> new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED)) .isInstanceOf(IllegalArgumentException.class); } @@ -414,9 +439,9 @@ void testInitializationWithAnUnknownClass() { void testGetDefaultKey() { RedisCacheInfo info = new RedisCacheInfo(); info.name = "test-default-key"; - info.ttl = Optional.of(Duration.ofSeconds(2)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(2)); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); assertThat(cache.getDefaultKey()).isEqualTo("default-cache-key"); assertThat(cache.getDefaultValueType()).isNull(); @@ -426,9 +451,9 @@ void testGetDefaultKey() { void testInvalidation() { RedisCacheInfo info = new RedisCacheInfo(); info.name = "test-invalidation"; - info.ttl = Optional.of(Duration.ofSeconds(10)); + info.expireAfterWrite = Optional.of(Duration.ofSeconds(10)); - RedisCacheImpl cache = new RedisCacheImpl<>(info, vertx, redis, BLOCKING_ALLOWED); + RedisCacheImpl cache = new RedisCacheImpl(info, vertx, redis, BLOCKING_ALLOWED); redis.send(Request.cmd(Command.SET).arg("key6").arg("my-value")).await().indefinitely();