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; package org.redisson.spring.cache;
import org.redisson.api.EvictionMode;
import org.redisson.api.map.event.MapEntryListener; import org.redisson.api.map.event.MapEntryListener;
import java.io.File; import java.io.File;
@ -39,7 +40,9 @@ public class CacheConfig {
private long maxIdleTime; private long maxIdleTime;
private int maxSize; private int maxSize;
private EvictionMode evictionMode = EvictionMode.LRU;
private final List<MapEntryListener> listeners = new ArrayList<>(); private final List<MapEntryListener> listeners = new ArrayList<>();
/** /**
@ -79,7 +82,6 @@ public class CacheConfig {
public void setTTL(long ttl) { public void setTTL(long ttl) {
this.ttl = ttl; this.ttl = ttl;
} }
public int getMaxSize() { public int getMaxSize() {
return maxSize; return maxSize;
@ -95,6 +97,21 @@ public class CacheConfig {
this.maxSize = maxSize; 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() { public long getMaxIdleTime() {
return maxIdleTime; return maxIdleTime;
} }

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

Loading…
Cancel
Save