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 b503b52a812bff5fbe9a56a51a16d93c5523bdf7
Author: Thomas Vandahl <[email protected]>
AuthorDate: Mon Sep 7 11:56:52 2026 +0200

    Handle maxObjects < 0 correctly
---
 .../jcs4/engine/memory/AbstractDoubleLinkedListMemoryCache.java        | 3 ++-
 .../org/apache/commons/jcs4/engine/memory/lru/LHMLRUMemoryCache.java   | 3 ++-
 2 files changed, 4 insertions(+), 2 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 9eb2bb25..f255cc61 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
@@ -248,8 +248,9 @@ public abstract class 
AbstractDoubleLinkedListMemoryCache<K, V> extends Abstract
         // need to pre-queue the queuing. This would be a bit wasteful
         // and wouldn't save much time in this synchronous call.
         final int size = getSize();
+        final int maxObjects = getCacheAttributes().MaxObjects();
         // If the element limit is reached, we need to spool
-        if (size <= getCacheAttributes().MaxObjects())
+        if (maxObjects < 0 || size <= maxObjects)
         {
             return;
         }
diff --git 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/lru/LHMLRUMemoryCache.java
 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/lru/LHMLRUMemoryCache.java
index a63f1d0e..08c7082a 100644
--- 
a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/lru/LHMLRUMemoryCache.java
+++ 
b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/lru/LHMLRUMemoryCache.java
@@ -71,8 +71,9 @@ public class LHMLRUMemoryCache<K, V>
         protected boolean removeEldestEntry( final Map.Entry<K, 
MemoryElementDescriptor<K, V>> eldest )
         {
             final ICacheElement<K, V> element = 
eldest.getValue().getCacheElement();
+            final int maxObjects = getCacheAttributes().MaxObjects();
 
-            if ( size() <= getCacheAttributes().MaxObjects() )
+            if (maxObjects < 0 || size() <= maxObjects)
             {
                 return false;
             }

Reply via email to