Skip to content

Commit 34ead2b

Browse files
committed
add support for concurrencyLevel in the CacheConfiguration
1 parent 34cd443 commit 34ead2b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

com.avaloq.tools.ddk/src/com/avaloq/tools/ddk/caching/CacheConfiguration.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class CacheConfiguration {
2222

2323
private long cacheSize = UNSET_INT;
2424
private int initialCapacity = UNSET_INT;
25+
private int concurrencyLevel = UNSET_INT;
2526

2627
/**
2728
* All values stored in the cache are wrapped as {@link java.lang.ref.SoftReference SoftReference}, allowing them to be garbage collected as necessary.
@@ -96,4 +97,17 @@ public CacheConfiguration setInitialCapacity(final int capacity) {
9697
public int getInitialCapacity() {
9798
return initialCapacity;
9899
}
100+
101+
public int getConcurrencyLevel() {
102+
return concurrencyLevel;
103+
}
104+
105+
/**
106+
* Setsthe concurrency level for the cache. Guava concurrent maps creates as many segments
107+
* as the specified concurrency level, each segment having its own lock.
108+
* If not set, a reasonable default is deternimed by the library according to the number of CPUs.
109+
*/
110+
public void setConcurrencyLevel(final int concurrencyLevel) {
111+
this.concurrencyLevel = concurrencyLevel;
112+
}
99113
}

com.avaloq.tools.ddk/src/com/avaloq/tools/ddk/caching/MapCache.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ public int weigh(final K key, final V value) {
7474
cacheBuilder.maximumSize(config.getMaximumSize());
7575
}
7676
}
77+
if (config.getConcurrencyLevel() >= 0) {
78+
cacheBuilder.concurrencyLevel(config.getConcurrencyLevel());
79+
}
7780
return cacheBuilder;
7881
}
7982

0 commit comments

Comments
 (0)