diff --git a/com.avaloq.tools.ddk/src/com/avaloq/tools/ddk/caching/CacheConfiguration.java b/com.avaloq.tools.ddk/src/com/avaloq/tools/ddk/caching/CacheConfiguration.java index 11ede1687..d16b02d40 100644 --- a/com.avaloq.tools.ddk/src/com/avaloq/tools/ddk/caching/CacheConfiguration.java +++ b/com.avaloq.tools.ddk/src/com/avaloq/tools/ddk/caching/CacheConfiguration.java @@ -18,6 +18,7 @@ public class CacheConfiguration { private boolean arraySize; private boolean softValues; + private boolean weakKeys; private boolean weakValues; private boolean statistics; @@ -45,6 +46,16 @@ public CacheConfiguration useWeakValues() { return this; } + /** + * All keys stored in the cache are wrapped as {@link java.lang.ref.SoftReference WeakReference}, allowing them to be garbage collected as necessary. + * + * @return the cache configuration + */ + public CacheConfiguration useWeakKeys() { + weakKeys = true; + return this; + } + /** * If enabled, the cache will treat the values as arrays and count their total entries when determining the maximum number of allowed entries. * @@ -85,6 +96,10 @@ public boolean isWeakValuesEnabled() { return weakValues; } + public boolean isWeakKeysEnabled() { + return weakKeys; + } + public boolean isStatisticsEnabled() { return statistics; } diff --git a/com.avaloq.tools.ddk/src/com/avaloq/tools/ddk/caching/MapCache.java b/com.avaloq.tools.ddk/src/com/avaloq/tools/ddk/caching/MapCache.java index 9ab32458b..acf8e041b 100644 --- a/com.avaloq.tools.ddk/src/com/avaloq/tools/ddk/caching/MapCache.java +++ b/com.avaloq.tools.ddk/src/com/avaloq/tools/ddk/caching/MapCache.java @@ -57,6 +57,11 @@ private CacheBuilder configure(final CacheConfiguration config) } else if (config.isWeakValuesEnabled()) { cacheBuilder.weakValues(); } + + if (config.isWeakKeysEnabled()) { + cacheBuilder.weakKeys(); + } + if (config.getInitialCapacity() >= 0) { cacheBuilder.initialCapacity(config.getInitialCapacity()); }