From 87bcfec6ede1da7bc2bdc906899ff94ac0fb6aeb Mon Sep 17 00:00:00 2001 From: Steve Draper Date: Fri, 28 Apr 2017 11:35:57 -0500 Subject: [PATCH] Added pre-warm mechanism for locally cached maps --- .../java/org/redisson/RedissonLocalCachedMap.java | 14 +++++++++++++- .../java/org/redisson/api/RLocalCachedMap.java | 7 ++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java index d81febe2e..efb981356 100644 --- a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java +++ b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java @@ -1084,7 +1084,19 @@ public class RedissonLocalCachedMap extends RedissonMap implements R return promise; } - + + @Override + public void preloadCache() { + // Best-attempt warmup - just enumerate as an uncached map (super) and + // add anything found into the cache. This does not guarantee to find + // entries added during the warmUp, but statistically the cache will have + // few misses after this process + for(Entry entry : super.entrySet()) { + CacheKey cacheKey = toCacheKey(entry.getKey()); + cache.put(cacheKey, new CacheValue(entry.getKey(), entry.getValue())); + } + } + @Override public RFuture>> readAllEntrySetAsync() { final Set> result = new HashSet>(); diff --git a/redisson/src/main/java/org/redisson/api/RLocalCachedMap.java b/redisson/src/main/java/org/redisson/api/RLocalCachedMap.java index a7f7ed9c6..43223cd1f 100644 --- a/redisson/src/main/java/org/redisson/api/RLocalCachedMap.java +++ b/redisson/src/main/java/org/redisson/api/RLocalCachedMap.java @@ -27,5 +27,10 @@ package org.redisson.api; * @param map value */ public interface RLocalCachedMap extends RMap, RDestroyable { - + /** + * Pre-warm the cached values. Not guaranteed to load ALL values, but statistically + * will preload approximately all (all if no concurrent mutating activity) + * Intended for use with no-eviction caches where entire maps are locally cached + */ + public void preloadCache(); }