From b49252ed6672e93681d32ea2d337b65dd6eb9603 Mon Sep 17 00:00:00 2001 From: guanchengang <115277968+guanchengang@users.noreply.github.com> Date: Fri, 18 Sep 2026 21:53:18 +0800 Subject: [PATCH] Avoid useless queue ops in ConcurrentLruCache.clear() ConcurrentLruCache.clear() previously drained write operations before cleaning up the cache. This could re-enqueue nodes that clear() was about to remove, causing useless evictionQueue operations. Now clear() iterates the cache values directly, removes and marks nodes as removed first, and drains write operations afterward. Since AddTask fails silently after a node is marked removed, this avoids the no-op work and improves performance. See gh-37287 Closes gh-37292 Signed-off-by: Chengang Guan --- .../java/org/springframework/util/ConcurrentLruCache.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java b/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java index acf38125ad3..f87e218af2f 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java @@ -189,13 +189,13 @@ public final class ConcurrentLruCache { public void clear() { this.evictionLock.lock(); try { - this.writeOperations.drainAll(); - Node node; - while ((node = this.evictionQueue.poll()) != null) { + for (Node node : this.cache.values()) { this.cache.remove(node.key, node); + this.evictionQueue.remove(node); markAsRemoved(node); } this.readOperations.clear(); + this.writeOperations.drainAll(); } finally { this.evictionLock.unlock();