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 3f03fc820a4443768c94ea846301007ba3911080
Author: Thomas Vandahl <[email protected]>
AuthorDate: Mon Sep 14 16:36:43 2026 +0200

    Make shards configurable, document the behaviour
---
 .../jcs4/engine/CompositeCacheAttributes.java      | 15 +++-
 .../engine/behavior/ICompositeCacheAttributes.java |  9 ++-
 .../jcs4/engine/TestCompositeCacheAttributes.java  | 85 ++++++++++++----------
 src/changes/changes.xml                            |  3 +
 src/site/xdoc/RegionProperties.xml                 |  9 +++
 5 files changed, 78 insertions(+), 43 deletions(-)

diff --git 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/CompositeCacheAttributes.java
 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/CompositeCacheAttributes.java
index 61003d08..e88fbf75 100644
--- 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/CompositeCacheAttributes.java
+++ 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/CompositeCacheAttributes.java
@@ -57,7 +57,10 @@ public record CompositeCacheAttributes(
         DiskUsagePatternEnum DiskUsagePattern,
 
         /** How many to spool to disk at a time. */
-        int SpoolChunkSize
+        int SpoolChunkSize,
+
+        /** Number of parallel accessible memory cache segments. */
+        int Shards
 ) implements ICompositeCacheAttributes
 {
     /** Don't change */
@@ -84,6 +87,9 @@ public record CompositeCacheAttributes(
     /** Default number to send to disk at a time when memory fills. */
     private static final int DEFAULT_CHUNK_SIZE = 2;
 
+    /** Default number of parallel accessible memory cache segments. */
+    private static final int DEFAULT_SHARDS = 1;
+
     /** Record with all defaults set */
     private static final CompositeCacheAttributes DEFAULT = new 
CompositeCacheAttributes(
             null,
@@ -94,7 +100,8 @@ public record CompositeCacheAttributes(
             DEFAULT_MAX_MEMORY_IDLE_TIME,
             DEFAULT_MEMORY_CACHE_NAME,
             DiskUsagePatternEnum.SWAP,
-            DEFAULT_CHUNK_SIZE
+            DEFAULT_CHUNK_SIZE,
+            DEFAULT_SHARDS
           );
 
     /**
@@ -121,7 +128,8 @@ public record CompositeCacheAttributes(
                 MaxMemoryIdleTime(),
                 MemoryCacheName(),
                 DiskUsagePattern(),
-                SpoolChunkSize());
+                SpoolChunkSize(),
+                Shards());
     }
 
     /**
@@ -138,6 +146,7 @@ public record CompositeCacheAttributes(
         dump.append( ", MaxSpoolPerRun = " ).append( MaxSpoolPerRun() );
         dump.append( ", DiskUsagePattern = " ).append( DiskUsagePattern() );
         dump.append( ", SpoolChunkSize = " ).append( SpoolChunkSize() );
+        dump.append( ", Shards = " ).append( Shards() );
         dump.append( " ]" );
 
         return dump.toString();
diff --git 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/behavior/ICompositeCacheAttributes.java
 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/behavior/ICompositeCacheAttributes.java
index d2a54e3a..7297bf8c 100644
--- 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/behavior/ICompositeCacheAttributes.java
+++ 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/behavior/ICompositeCacheAttributes.java
@@ -94,10 +94,17 @@ public interface ICompositeCacheAttributes
     /**
      * Number to send to disk at time when memory is full.
      *
-     * @return int
+     * @return number of items to spool at a time
      */
     int SpoolChunkSize();
 
+    /**
+     * Number of parallel accessible memory cache segments.
+     *
+     * @return number of memory cache shards
+     */
+    int Shards();
+
     /**
      * Tests whether the memory cache should perform background memory 
shrinkage.
      *
diff --git 
a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/TestCompositeCacheAttributes.java
 
b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/TestCompositeCacheAttributes.java
index 1f512815..cda3a93a 100644
--- 
a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/TestCompositeCacheAttributes.java
+++ 
b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/TestCompositeCacheAttributes.java
@@ -1,7 +1,5 @@
 package org.apache.commons.jcs4.engine;
 
-import java.time.Duration;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,6 +19,10 @@ import java.time.Duration;
  * under the License.
  */
 
+import static org.apache.commons.jcs4.engine.CompositeCacheAttributes.defaults;
+
+import java.time.Duration;
+
 import org.apache.commons.jcs4.engine.behavior.ICompositeCacheAttributes;
 
 /**
@@ -40,15 +42,16 @@ public class TestCompositeCacheAttributes
      */
     public static CompositeCacheAttributes 
withMemoryCacheNameAndMaxObjects(String memoryCacheName, int maxObjects)
     {
-        return new 
CompositeCacheAttributes(CompositeCacheAttributes.defaults().cacheName(),
+        return new CompositeCacheAttributes(defaults().cacheName(),
                 maxObjects,
-                CompositeCacheAttributes.defaults().UseMemoryShrinker(),
-                CompositeCacheAttributes.defaults().ShrinkerInterval(),
-                CompositeCacheAttributes.defaults().MaxSpoolPerRun(),
-                CompositeCacheAttributes.defaults().MaxMemoryIdleTime(),
+                defaults().UseMemoryShrinker(),
+                defaults().ShrinkerInterval(),
+                defaults().MaxSpoolPerRun(),
+                defaults().MaxMemoryIdleTime(),
                 memoryCacheName,
-                CompositeCacheAttributes.defaults().DiskUsagePattern(),
-                CompositeCacheAttributes.defaults().SpoolChunkSize());
+                defaults().DiskUsagePattern(),
+                defaults().SpoolChunkSize(),
+                defaults().Shards());
     }
 
     /**
@@ -61,15 +64,16 @@ public class TestCompositeCacheAttributes
     public static CompositeCacheAttributes 
withMemoryCacheNameMaxMemoryIdleTimeAndMaxSpoolPerRun(
             String memoryCacheName, Duration maxMemoryIdleTime, int 
maxSpoolPerRun)
     {
-        return new 
CompositeCacheAttributes(CompositeCacheAttributes.defaults().cacheName(),
-                CompositeCacheAttributes.defaults().MaxObjects(),
-                CompositeCacheAttributes.defaults().UseMemoryShrinker(),
-                CompositeCacheAttributes.defaults().ShrinkerInterval(),
+        return new CompositeCacheAttributes(defaults().cacheName(),
+                defaults().MaxObjects(),
+                defaults().UseMemoryShrinker(),
+                defaults().ShrinkerInterval(),
                 maxSpoolPerRun,
                 maxMemoryIdleTime,
                 memoryCacheName,
-                CompositeCacheAttributes.defaults().DiskUsagePattern(),
-                CompositeCacheAttributes.defaults().SpoolChunkSize());
+                defaults().DiskUsagePattern(),
+                defaults().SpoolChunkSize(),
+                defaults().Shards());
     }
 
     /**
@@ -80,15 +84,16 @@ public class TestCompositeCacheAttributes
      */
     public static CompositeCacheAttributes withMaxObjectsAndSpoolChunkSize(int 
maxObjects, int spoolChunkSize)
     {
-        return new 
CompositeCacheAttributes(CompositeCacheAttributes.defaults().cacheName(),
+        return new CompositeCacheAttributes(defaults().cacheName(),
                 maxObjects,
-                CompositeCacheAttributes.defaults().UseMemoryShrinker(),
-                CompositeCacheAttributes.defaults().ShrinkerInterval(),
-                CompositeCacheAttributes.defaults().MaxSpoolPerRun(),
-                CompositeCacheAttributes.defaults().MaxMemoryIdleTime(),
-                CompositeCacheAttributes.defaults().MemoryCacheName(),
-                CompositeCacheAttributes.defaults().DiskUsagePattern(),
-                spoolChunkSize);
+                defaults().UseMemoryShrinker(),
+                defaults().ShrinkerInterval(),
+                defaults().MaxSpoolPerRun(),
+                defaults().MaxMemoryIdleTime(),
+                defaults().MemoryCacheName(),
+                defaults().DiskUsagePattern(),
+                spoolChunkSize,
+                defaults().Shards());
     }
 
     /**
@@ -98,15 +103,16 @@ public class TestCompositeCacheAttributes
      */
     public static CompositeCacheAttributes withMaxMemoryIdleTime(Duration 
maxMemoryIdleTime)
     {
-        return new 
CompositeCacheAttributes(CompositeCacheAttributes.defaults().cacheName(),
-                CompositeCacheAttributes.defaults().MaxObjects(),
-                CompositeCacheAttributes.defaults().UseMemoryShrinker(),
-                CompositeCacheAttributes.defaults().ShrinkerInterval(),
-                CompositeCacheAttributes.defaults().MaxSpoolPerRun(),
+        return new CompositeCacheAttributes(defaults().cacheName(),
+                defaults().MaxObjects(),
+                defaults().UseMemoryShrinker(),
+                defaults().ShrinkerInterval(),
+                defaults().MaxSpoolPerRun(),
                 maxMemoryIdleTime,
-                CompositeCacheAttributes.defaults().MemoryCacheName(),
-                CompositeCacheAttributes.defaults().DiskUsagePattern(),
-                CompositeCacheAttributes.defaults().SpoolChunkSize());
+                defaults().MemoryCacheName(),
+                defaults().DiskUsagePattern(),
+                defaults().SpoolChunkSize(),
+                defaults().Shards());
     }
 
     /**
@@ -116,14 +122,15 @@ public class TestCompositeCacheAttributes
      */
     public static CompositeCacheAttributes 
withDiskUsagePattern(ICompositeCacheAttributes.DiskUsagePatternEnum 
diskUsagePattern)
     {
-        return new 
CompositeCacheAttributes(CompositeCacheAttributes.defaults().cacheName(),
-                CompositeCacheAttributes.defaults().MaxObjects(),
-                CompositeCacheAttributes.defaults().UseMemoryShrinker(),
-                CompositeCacheAttributes.defaults().ShrinkerInterval(),
-                CompositeCacheAttributes.defaults().MaxSpoolPerRun(),
-                CompositeCacheAttributes.defaults().MaxMemoryIdleTime(),
-                CompositeCacheAttributes.defaults().MemoryCacheName(),
+        return new CompositeCacheAttributes(defaults().cacheName(),
+                defaults().MaxObjects(),
+                defaults().UseMemoryShrinker(),
+                defaults().ShrinkerInterval(),
+                defaults().MaxSpoolPerRun(),
+                defaults().MaxMemoryIdleTime(),
+                defaults().MemoryCacheName(),
                 diskUsagePattern,
-                CompositeCacheAttributes.defaults().SpoolChunkSize());
+                defaults().SpoolChunkSize(),
+                defaults().Shards());
     }
 }
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d7c2b213..c181ab79 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -50,6 +50,9 @@
                fix typo "waterfal" method
             </action>
             <!-- ADD -->
+            <action dev="tv" type="add">
+               Add configurable memory cache sharding for improved concurrent 
performance
+            </action>
             <action type="add" dev="ggregory" due-to="Gary Gregory">
                Add Maven property project.build.outputTimestamp for build 
reproducibility.
             </action>
diff --git a/src/site/xdoc/RegionProperties.xml 
b/src/site/xdoc/RegionProperties.xml
index dd5cedaa..51ac6b28 100644
--- a/src/site/xdoc/RegionProperties.xml
+++ b/src/site/xdoc/RegionProperties.xml
@@ -187,6 +187,15 @@
                         </td>
                         <td>N</td>
                         <td>2</td>
+                    </tr>
+                    <tr>
+                        <td>Shards</td>
+                        <td>
+                            Number of memory cache segments to improve
+                            concurrent performance.
+                        </td>
+                        <td>N</td>
+                        <td>1</td>
                     </tr>
                                </table>
                        </subsection>

Reply via email to