diff --git a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java index 79054717c..fa3b47132 100644 --- a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java +++ b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java @@ -207,18 +207,8 @@ public class RedissonLocalCachedMap extends RedissonMap implements R if (options.isInvalidateEntryOnChange()) { invalidateEntryOnChange = 1; } - if (options.getEvictionPolicy() == EvictionPolicy.NONE) { - cache = new NoneCacheMap(options.getTimeToLiveInMillis(), options.getMaxIdleInMillis()); - } - if (options.getEvictionPolicy() == EvictionPolicy.LRU) { - cache = new LRUCacheMap(options.getCacheSize(), options.getTimeToLiveInMillis(), options.getMaxIdleInMillis()); - } - if (options.getEvictionPolicy() == EvictionPolicy.LFU) { - cache = new LFUCacheMap(options.getCacheSize(), options.getTimeToLiveInMillis(), options.getMaxIdleInMillis()); - } - if (options.getEvictionPolicy() == EvictionPolicy.SOFT) { - cache = new SoftCacheMap(options.getTimeToLiveInMillis(), options.getMaxIdleInMillis()); - } + + cache = createCache(options); invalidationTopic = new RedissonTopic(commandExecutor, suffixName(name, "topic")); if (options.isInvalidateEntryOnChange()) { @@ -241,6 +231,22 @@ public class RedissonLocalCachedMap extends RedissonMap implements R }); } } + + protected Cache createCache(LocalCachedMapOptions options) { + if (options.getEvictionPolicy() == EvictionPolicy.NONE) { + return new NoneCacheMap(options.getTimeToLiveInMillis(), options.getMaxIdleInMillis()); + } + if (options.getEvictionPolicy() == EvictionPolicy.LRU) { + return new LRUCacheMap(options.getCacheSize(), options.getTimeToLiveInMillis(), options.getMaxIdleInMillis()); + } + if (options.getEvictionPolicy() == EvictionPolicy.LFU) { + return new LFUCacheMap(options.getCacheSize(), options.getTimeToLiveInMillis(), options.getMaxIdleInMillis()); + } + if (options.getEvictionPolicy() == EvictionPolicy.SOFT) { + return new SoftCacheMap(options.getTimeToLiveInMillis(), options.getMaxIdleInMillis()); + } + throw new IllegalArgumentException("Invalid eviction policy: " + options.getEvictionPolicy()); + } private CacheKey toCacheKey(Object key) { byte[] encoded = encodeMapKey(key);