mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-24 15:49:26 +00:00
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 <guanchengang@qq.com>
This commit is contained in:
@@ -189,13 +189,13 @@ public final class ConcurrentLruCache<K, V> {
|
||||
public void clear() {
|
||||
this.evictionLock.lock();
|
||||
try {
|
||||
this.writeOperations.drainAll();
|
||||
Node<K, V> node;
|
||||
while ((node = this.evictionQueue.poll()) != null) {
|
||||
for (Node<K, V> 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();
|
||||
|
||||
Reference in New Issue
Block a user