Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.apache.shenyu.admin.model.entity.ScaleRuleDO;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

@Component
Expand Down Expand Up @@ -56,6 +58,20 @@ public void removeRulesFromCache(final List<String> metricNames) {
metricNames.forEach(ruleCache::remove);
}

/**
* Removes rules from cache by their primary keys.
*
* @param ids rule primary keys
*/
public void removeRulesByIdsFromCache(final List<String> ids) {
final Set<String> idSet = new HashSet<>(ids);
ruleCache.forEach((metricName, rule) -> {
if (idSet.contains(rule.getId())) {
ruleCache.remove(metricName, rule);
}
});
}

/**
* getAllRules.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public int update(final ScaleRuleDTO scaleRuleDTO) {
public int delete(final List<String> ids) {
int rows = scaleRuleMapper.delete(ids);
if (rows > 0) {
scaleRuleCache.removeRulesFromCache(ids);
scaleRuleCache.removeRulesByIdsFromCache(ids);
}
return rows;
}
Expand Down
Loading