Skip to content

Commit bee091e

Browse files
authored
fix(cache2k): create unbounded cache if maxSize is not specified (#184)
1 parent 405af01 commit bee091e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

provider-cache2k/src/main/java/io/github/xanthic/cache/provider/cache2k/Cache2kProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ public <K, V> Cache<K, V> build(ICacheSpec<K, V> spec) {
3535
Cache2kBuilder<K, V> builder = (Cache2kBuilder<K, V>) Cache2kBuilder.forUnknownTypes()
3636
.disableStatistics(true); // avoid performance penalty since we don't offer an interface for these statistics
3737

38-
if (spec.maxSize() != null) builder.entryCapacity(spec.maxSize());
38+
if (spec.maxSize() != null) {
39+
builder.entryCapacity(spec.maxSize());
40+
} else {
41+
// We must specify MAX_VALUE to create an unbounded cache to comply with the Xanthic maxSize spec
42+
// since Cache2k, by default, imposes a capacity bound of 1802 (Cache2kConfig#DEFAULT_ENTRY_CAPACITY)
43+
builder.entryCapacity(Long.MAX_VALUE);
44+
}
3945

4046
ScheduledExecutorService exec = populateExecutor(builder, spec.executor());
4147

0 commit comments

Comments
 (0)