[BUG] Selector/rule match-cache positive hit is discarded (cache defeated for the success path)
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
## Description
The L1 match cache is consulted for a *negative* hit only. When the cache returns a *positive* match (a `SelectorData`/`RuleData` with a non-blank id), the guard `if (Objects.nonNull(selectorData) && StringUtils.isBlank(selectorData.getId()))` is false, so control falls through to `defaultMatchSelector(...)`/`defaultMatchRule(...)` which **unconditionally re-runs the full condition match and overwrites the cached value**. The cached positive match is never used. The code comments at lines 121-123 describe the intended design (L1 cache hit short-circuits). Note the two guards are also inconsistent: the selector uses `StringUtils.isBlank`, the rule uses `Objects.isNull`.
## Location
```
shenyu-plugin-base/.../AbstractShenyuPlugin.java:97-105 (selector), 124-131 (rule)
```
## Impact
The match cache provides zero benefit for the hot/success path — it only works as a negative cache. This defeats the primary purpose of `selectorMatchCache`/`ruleMatchCache` and is the dominant per-request CPU cost on the matching path.
## Suggested fix
After the negative-cache guard, add a positive-cache branch: if the cached entry is non-null with a non-blank id, use it directly. Apply symmetrically to selector and rule.
## Related existing issue(s)
#5290 (closed) was about a match error, not positive-hit discard; #5044 (closed) was a cache-enhancement task. Not a dup.
_Identified during the 2026-08-02 audit; full list in [`docs/issue-candidates-2026-08-02.md`](docs/issue-candidates-2026-08-02.md)._
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in shenyu-plugin-base/.../AbstractShenyuPlugin.java at the selector and rule matching sections, and read the guards around defaultMatchSelector(...) and defaultMatchRule(...), along with the comments at lines 121-123. Verify that positive L1 cache entries are used for both paths without rerunning the full condition match, while negative-cache behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend, performance
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100