Merge pull request #6418 from JKord/improve-cacheConfig

Add ability to set eviction mode for Cache Config
pull/6415/head^2
Nikita Koksharov 3 weeks ago committed by GitHub
commit 7dc4d31d7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -15,6 +15,7 @@
*/
package org.redisson.spring.cache;
import org.redisson.api.EvictionMode;
import org.redisson.api.map.event.MapEntryListener;
import java.io.File;
@ -39,7 +40,9 @@ public class CacheConfig {
private long maxIdleTime;
private int maxSize;
private EvictionMode evictionMode = EvictionMode.LRU;
private final List<MapEntryListener> listeners = new ArrayList<>();
/**
@ -79,7 +82,6 @@ public class CacheConfig {
public void setTTL(long ttl) {
this.ttl = ttl;
}
public int getMaxSize() {
return maxSize;
@ -95,6 +97,21 @@ public class CacheConfig {
this.maxSize = maxSize;
}
public EvictionMode getEvictionMode() {
return evictionMode;
}
/**
* Set the eviction mode of the map. Superfluous elements are evicted using LRU or LFU algorithm.
*
* @param evictionMode - eviction mode (LRU, LFU)
* @return
*/
public CacheConfig setEvictionMode(EvictionMode evictionMode) {
this.evictionMode = evictionMode;
return this;
}
public long getMaxIdleTime() {
return maxIdleTime;
}

@ -269,7 +269,7 @@ public class RedissonSpringCacheManager implements CacheManager, ResourceLoaderA
if (oldCache != null) {
cache = oldCache;
} else {
map.setMaxSize(config.getMaxSize());
map.setMaxSize(config.getMaxSize(), config.getEvictionMode());
for (MapEntryListener listener : config.getListeners()) {
map.addListener(listener);
}

Loading…
Cancel
Save