Added pre-warm mechanism for locally cached maps

pull/873/head
Steve Draper 8 years ago
parent 35153462b0
commit 87bcfec6ed

@ -1084,7 +1084,19 @@ public class RedissonLocalCachedMap<K, V> extends RedissonMap<K, V> implements R
return promise; 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<K,V> entry : super.entrySet()) {
CacheKey cacheKey = toCacheKey(entry.getKey());
cache.put(cacheKey, new CacheValue(entry.getKey(), entry.getValue()));
}
}
@Override @Override
public RFuture<Set<Entry<K, V>>> readAllEntrySetAsync() { public RFuture<Set<Entry<K, V>>> readAllEntrySetAsync() {
final Set<Entry<K, V>> result = new HashSet<Entry<K, V>>(); final Set<Entry<K, V>> result = new HashSet<Entry<K, V>>();

@ -27,5 +27,10 @@ package org.redisson.api;
* @param <V> map value * @param <V> map value
*/ */
public interface RLocalCachedMap<K, V> extends RMap<K, V>, RDestroyable { public interface RLocalCachedMap<K, V> extends RMap<K, V>, 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();
} }

Loading…
Cancel
Save