Add maxSize setting for SpringCacheManager #1067

pull/1068/head
Nikita 7 years ago
parent 221bca7593
commit 4cd534d045

@ -33,6 +33,8 @@ public class CacheConfig {
private long ttl;
private long maxIdleTime;
private int maxSize;
/**
* Creates config object with
@ -72,6 +74,21 @@ public class CacheConfig {
this.ttl = ttl;
}
public int getMaxSize() {
return maxSize;
}
/**
* Set max size of map. Superfluous elements are evicted using LRU algorithm.
*
* @param maxSize - max size
* If <code>0</code> the cache is unbounded (default).
*/
public void setMaxSize(int maxSize) {
this.maxSize = maxSize;
}
public long getMaxIdleTime() {
return maxIdleTime;
}

@ -216,7 +216,7 @@ public class RedissonSpringCacheManager implements CacheManager, ResourceLoaderA
return createMap(name, config);
}
if (config.getMaxIdleTime() == 0 && config.getTTL() == 0) {
if (config.getMaxIdleTime() == 0 && config.getTTL() == 0 && config.getMaxSize() == 0) {
return createMap(name, config);
}
@ -248,6 +248,8 @@ public class RedissonSpringCacheManager implements CacheManager, ResourceLoaderA
Cache oldCache = instanceMap.putIfAbsent(name, cache);
if (oldCache != null) {
cache = oldCache;
} else {
map.setMaxSize(config.getMaxSize());
}
return cache;
}

Loading…
Cancel
Save