From 86f5dfd581c51475503a5e4b3445a7616d8c04f6 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Mon, 19 Apr 2021 11:09:14 +0300 Subject: [PATCH] Feature - getWithTTLOnly() method to RMapCache object #3558 Feature - add method to update ttl and idleTime of entry by key. #3423 --- .../org/redisson/api/RMapCacheReactive.java | 38 +++++++++++++++++++ .../java/org/redisson/api/RMapCacheRx.java | 38 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/redisson/src/main/java/org/redisson/api/RMapCacheReactive.java b/redisson/src/main/java/org/redisson/api/RMapCacheReactive.java index 581500cd6..49e0ca2df 100644 --- a/redisson/src/main/java/org/redisson/api/RMapCacheReactive.java +++ b/redisson/src/main/java/org/redisson/api/RMapCacheReactive.java @@ -17,6 +17,7 @@ package org.redisson.api; import java.util.concurrent.TimeUnit; +import org.redisson.api.map.MapLoader; import reactor.core.publisher.Mono; /** @@ -215,6 +216,43 @@ public interface RMapCacheReactive extends RMapReactive, RDestroyabl */ Mono fastPutIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit); + /** + * Updates time to live and max idle time of specified entry by key. + * Entry expires when specified time to live or max idle time was reached. + *

+ * Returns false if entry already expired or doesn't exist, + * otherwise returns true. + * + * @param key - map key + * @param ttl - time to live for key\value entry. + * If 0 then time to live doesn't affect entry expiration. + * @param ttlUnit - time unit + * @param maxIdleTime - max idle time for key\value entry. + * If 0 then max idle time doesn't affect entry expiration. + * @param maxIdleUnit - time unit + *

+ * if maxIdleTime and ttl params are equal to 0 + * then entry stores infinitely. + * + * @return returns false if entry already expired or doesn't exist, + * otherwise returns true. + */ + Mono updateEntryExpiration(K key, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit); + + /** + * Returns the value mapped by defined key or {@code null} if value is absent. + *

+ * If map doesn't contain value for specified key and {@link MapLoader} is defined + * then value will be loaded in read-through mode. + *

+ * Idle time of entry is not taken into account. + * Entry last access time isn't modified if map limited by size. + * + * @param key the key + * @return the value mapped by defined key or {@code null} if value is absent + */ + Mono getWithTTLOnly(K key); + /** * Returns the number of entries in cache. * This number can reflects expired entries too diff --git a/redisson/src/main/java/org/redisson/api/RMapCacheRx.java b/redisson/src/main/java/org/redisson/api/RMapCacheRx.java index 657da71f2..8f98a0f09 100644 --- a/redisson/src/main/java/org/redisson/api/RMapCacheRx.java +++ b/redisson/src/main/java/org/redisson/api/RMapCacheRx.java @@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit; import io.reactivex.rxjava3.core.Completable; import io.reactivex.rxjava3.core.Maybe; import io.reactivex.rxjava3.core.Single; +import org.redisson.api.map.MapLoader; /** *

Map-based cache with ability to set TTL for each entry via @@ -217,6 +218,43 @@ public interface RMapCacheRx extends RMapRx, RDestroyable { */ Single fastPutIfAbsent(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit); + /** + * Updates time to live and max idle time of specified entry by key. + * Entry expires when specified time to live or max idle time was reached. + *

+ * Returns false if entry already expired or doesn't exist, + * otherwise returns true. + * + * @param key - map key + * @param ttl - time to live for key\value entry. + * If 0 then time to live doesn't affect entry expiration. + * @param ttlUnit - time unit + * @param maxIdleTime - max idle time for key\value entry. + * If 0 then max idle time doesn't affect entry expiration. + * @param maxIdleUnit - time unit + *

+ * if maxIdleTime and ttl params are equal to 0 + * then entry stores infinitely. + * + * @return returns false if entry already expired or doesn't exist, + * otherwise returns true. + */ + Single updateEntryExpiration(K key, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit); + + /** + * Returns the value mapped by defined key or {@code null} if value is absent. + *

+ * If map doesn't contain value for specified key and {@link MapLoader} is defined + * then value will be loaded in read-through mode. + *

+ * Idle time of entry is not taken into account. + * Entry last access time isn't modified if map limited by size. + * + * @param key the key + * @return the value mapped by defined key or {@code null} if value is absent + */ + Maybe getWithTTLOnly(K key); + /** * Returns the number of entries in cache. * This number can reflects expired entries too