Feature - added max-size setting for Quarkus Cache.

pull/1461/merge
mrniko 1 month ago
parent 8036876570
commit 34b4c02f88

@ -67,8 +67,8 @@ public class RedissonCacheBuildRecorder {
for (RedissonCacheInfo cacheInfo : cacheInfos) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debugf(
"Building Redis cache [%s] with [expireAfterAccess=%s], [expireAfterWrite=%s]",
cacheInfo.name, cacheInfo.expireAfterAccess, cacheInfo.expireAfterWrite);
"Building Redis cache [%s] with [expireAfterAccess=%s], [expireAfterWrite=%s], [maxSize=%s]",
cacheInfo.name, cacheInfo.expireAfterAccess, cacheInfo.expireAfterWrite, cacheInfo.maxSize);
}
RedissonCacheImpl cache = new RedissonCacheImpl(cacheInfo);

@ -51,14 +51,22 @@ public class RedissonCacheImpl extends AbstractCache implements RedissonCache {
CacheImplementation impl = cacheInfo.implementation.orElse(CacheImplementation.STANDARD);
this.cacheInfo = cacheInfo;
if (cacheInfo.expireAfterAccess.isPresent()
|| cacheInfo.expireAfterWrite.isPresent()) {
|| cacheInfo.expireAfterWrite.isPresent()
|| cacheInfo.maxSize.isPresent()) {
if (impl == CacheImplementation.STANDARD) {
this.mapCache = redisson.getMapCache(cacheInfo.name);
this.map = this.mapCache;
if (cacheInfo.maxSize.isPresent()) {
mapCache.setMaxSizeAsync(cacheInfo.maxSize.orElse(0));
}
} else if (impl == CacheImplementation.NATIVE) {
if (cacheInfo.expireAfterAccess.isPresent()) {
throw new IllegalArgumentException("expireAfterAccess isn't supported by NATIVE implementation");
}
if (cacheInfo.maxSize.isPresent()) {
throw new IllegalArgumentException("maxSize isn't supported by NATIVE implementation");
}
this.mapCacheNative = redisson.getMapCacheNative(cacheInfo.name);
this.map = this.mapCacheNative;
} else {

@ -25,6 +25,12 @@ import java.util.Optional;
*/
public class RedissonCacheInfo {
/**
* The maximum size of this cache.
* Superfluous elements are evicted using LRU algorithm.
*/
public Optional<Integer> maxSize = Optional.empty();
/**
* The cache name
*/

@ -61,6 +61,12 @@ public class RedissonCacheInfoBuilder {
cacheInfo.expireAfterWrite = defaultRuntimeConfig.expireAfterWrite;
}
if (namedRuntimeConfig != null && namedRuntimeConfig.maxSize.isPresent()) {
cacheInfo.maxSize = namedRuntimeConfig.maxSize;
} else if (defaultRuntimeConfig.maxSize.isPresent()) {
cacheInfo.maxSize = defaultRuntimeConfig.maxSize;
}
result.add(cacheInfo);
}
return result;

@ -29,6 +29,14 @@ import java.util.Optional;
@ConfigGroup
public class RedissonCacheRuntimeConfig {
/**
* Specifies maximum size of this cache.
* Superfluous elements are evicted using LRU algorithm.
* If <code>0</code> the cache is unbounded (default).
*/
@ConfigItem
Optional<Integer> maxSize;
/**
* Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after
* the entry's creation, or the most recent replacement of its value.

Loading…
Cancel
Save