Add maxSize setting for SpringCacheManager #1067

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

@ -34,6 +34,8 @@ public class CacheConfig {
private long maxIdleTime; private long maxIdleTime;
private int maxSize;
/** /**
* Creates config object with * Creates config object with
* <code>ttl = 0</code> and <code>maxIdleTime = 0</code>. * <code>ttl = 0</code> and <code>maxIdleTime = 0</code>.
@ -72,6 +74,21 @@ public class CacheConfig {
this.ttl = ttl; 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() { public long getMaxIdleTime() {
return maxIdleTime; return maxIdleTime;
} }

@ -216,7 +216,7 @@ public class RedissonSpringCacheManager implements CacheManager, ResourceLoaderA
return createMap(name, config); 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); return createMap(name, config);
} }
@ -248,6 +248,8 @@ public class RedissonSpringCacheManager implements CacheManager, ResourceLoaderA
Cache oldCache = instanceMap.putIfAbsent(name, cache); Cache oldCache = instanceMap.putIfAbsent(name, cache);
if (oldCache != null) { if (oldCache != null) {
cache = oldCache; cache = oldCache;
} else {
map.setMaxSize(config.getMaxSize());
} }
return cache; return cache;
} }

Loading…
Cancel
Save