This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new 82a29fcd67 Fix the bug in LFUCache#put() method (#11538)
82a29fcd67 is described below

commit 82a29fcd674216fe9bea10b6efef3196929dd7ca
Author: why技术 <[email protected]>
AuthorDate: Tue Feb 14 14:52:37 2023 +0800

    Fix the bug in LFUCache#put() method (#11538)
    
    We should not adopt the scheme of "first put new elements, then judge the 
capacity, and if it is full, trigger the proceedEviction() method".Instead, we 
should adopt the scheme of "first determine the capacity, then trigger the 
proceedEviction() method if it is full, and finally put in new elements".
---
 .../src/main/java/org/apache/dubbo/common/utils/LFUCache.java         | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/LFUCache.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/LFUCache.java
index ddcf2e62ea..22a15dbdfe 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/LFUCache.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/LFUCache.java
@@ -85,12 +85,12 @@ public class LFUCache<K, V> {
                 freqTable[0].addLastNode(node);
                 map.put(key, node);
             } else {
-                node = freqTable[0].addLast(key, value);
-                map.put(key, node);
                 curSize++;
                 if (curSize > capacity) {
                     proceedEviction();
                 }
+                node = freqTable[0].addLast(key, value);
+                map.put(key, node);
             }
         } finally {
             lock.unlock();

Reply via email to