This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
commit 76eab4d373fb6dedd69de512134ee6b13385d134 Author: Thomas Vandahl <[email protected]> AuthorDate: Fri Sep 4 15:37:15 2026 +0200 Better data encapsulation --- .../AbstractDoubleLinkedListMemoryCache.java | 4 +-- .../jcs4/engine/memory/AbstractMemoryCache.java | 33 ++++++++-------------- .../jcs4/engine/memory/behavior/IMemoryCache.java | 7 ----- .../jcs4/engine/memory/MockMemoryCache.java | 7 ----- 4 files changed, 13 insertions(+), 38 deletions(-) diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractDoubleLinkedListMemoryCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractDoubleLinkedListMemoryCache.java index 031ece0c..1de4c48b 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractDoubleLinkedListMemoryCache.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractDoubleLinkedListMemoryCache.java @@ -347,10 +347,10 @@ public abstract class AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract { throw new Error("update: last.ce is null!"); } - getCompositeCache().spoolToDisk(toSpool); + waterfall(toSpool); if (map.remove(toSpool.key()) == null) { - log.warn("update: remove failed for key: {0}", toSpool.key()); + log.warn("update: remove failed for key: {0}", toSpool::key); if (log.isTraceEnabled()) { diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractMemoryCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractMemoryCache.java index 346f164b..2a34cbaf 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractMemoryCache.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/AbstractMemoryCache.java @@ -28,6 +28,7 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Consumer; import java.util.stream.Collectors; import org.apache.commons.jcs4.engine.behavior.ICache; @@ -54,8 +55,11 @@ public abstract class AbstractMemoryCache<K, V> /** Cache Attributes. Regions settings. */ private ICompositeCacheAttributes cacheAttributes; - /** The cache region this store is associated with */ - private CompositeCache<K, V> cache; + /** The cache region spool method */ + private Consumer<ICacheElement<K,V>> waterfall; + + /** The cache region name this store is associated with */ + private String cacheName; /** How many to spool at a time. */ protected int chunkSize; @@ -175,23 +179,7 @@ public abstract class AbstractMemoryCache<K, V> */ public String getCacheName() { - final String attributeCacheName = this.cacheAttributes.cacheName(); - if(attributeCacheName != null) - { - return attributeCacheName; - } - return cache.getCacheName(); - } - - /** - * Gets the cache hub / region that the MemoryCache is used by - * - * @return The cache value - */ - @Override - public CompositeCache<K, V> getCompositeCache() - { - return this.cache; + return cacheName; } /** @@ -311,8 +299,9 @@ public abstract class AbstractMemoryCache<K, V> this.cacheAttributes = hub.getCacheAttributes(); this.chunkSize = cacheAttributes.SpoolChunkSize(); - this.cache = hub; - + final String attributeCacheName = this.cacheAttributes.cacheName(); + this.cacheName = attributeCacheName == null ? hub.getCacheName() : attributeCacheName; + this.waterfall = ce -> hub.spoolToDisk(ce); this.map = createMap(); } @@ -501,6 +490,6 @@ public abstract class AbstractMemoryCache<K, V> @Override public void waterfall( final ICacheElement<K, V> ce ) { - this.cache.spoolToDisk( ce ); + this.waterfall.accept(ce); } } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/behavior/IMemoryCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/behavior/IMemoryCache.java index f86a3569..e5d31f92 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/behavior/IMemoryCache.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/behavior/IMemoryCache.java @@ -72,13 +72,6 @@ public interface IMemoryCache<K, V> */ ICompositeCacheAttributes getCacheAttributes(); - /** - * Gets the cache hub / region that uses the MemoryCache. - * - * @return The cache value - */ - CompositeCache<K, V> getCompositeCache(); - /** * Gets a set of the keys for all elements in the memory cache. * diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/memory/MockMemoryCache.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/memory/MockMemoryCache.java index db86d540..2fc2b8fc 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/memory/MockMemoryCache.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/memory/MockMemoryCache.java @@ -95,13 +95,6 @@ public class MockMemoryCache<K, V> return cacheAttr; } - /** @return null */ - @Override - public CompositeCache<K, V> getCompositeCache() - { - return null; - } - /** * @param group * @return null
