Repository navigation
fix(plugin): bound match cache entries with configurable TTL (#7651) - #7664
Conversation
…7651) Signed-off-by: jerry <[email protected]>
Aias00
left a comment
There was a problem hiding this comment.
Summary
This is exactly the fix proposed in #7651 — thank you for picking it up.
I verified the critical detail that is easy to get wrong: WindowTinyLFUMap's four-arg constructor signature is (initialSize, expireAfterWrite, maximumSize, weakKey), and this PR calls new WindowTinyLFUMap<>(initialCapacity, ttl, maximumSize, Boolean.FALSE). So the TTL is correctly wired into expireAfterWrite(...) rather than accidentally mapping onto maximumSize.
ShenyuConfig.MatchCacheConfig.ttl(default 60000ms) with positive-value validation.AbstractShenyuPluginthreads the TTL throughcacheSelectorData/cacheRuleData.MatchDataCacheadds the TTL overload and uses the four-argWindowTinyLFUMap; the old three-arg overload is kept (delegating to the default TTL) for backward compatibility.testPositiveAndNegativeMatchesExpireverifies both positive and negative (empty-id) entries expire within the TTL viaAwaitility.
This closes the staleness gap described in #7651 (time-based self-healing when a data-sync event is missed) while leaving the event-driven invalidation path untouched.
Non-blocking
- The per-plugin
WindowTinyLFUMapis created with the TTL at first-write time; a later change to thettlconfig value does not retroactively apply to already-created maps. Acceptable (config changes effectively require a restart of the cache lifecycle), but worth a line in the docs/release notes.
CI
All build (shenyu-integrated-test-*) jobs pass; only k8s-examples-http (k8s infrastructure) fails, unrelated.
Approving.
Fixes #7651.
MatchDataCache currently retains positive and negative matches until eviction or event-driven invalidation. Add expire-after-write to selector and rule caches with a 60-second default. Configure each independently through
shenyu.selectorMatchCache.cache.ttlandshenyu.ruleMatchCache.cache.ttl(positive milliseconds). Existing cache methods remain available and use the default lifetime. Bootstrap YAML comments describe the reuse/staleness trade-off; event-driven invalidation remains unchanged.TTL bounds reuse of derived match results. It cannot recover a missed update to BaseDataCache itself: expiration rematches against the gateway's current local configuration. Caffeine stops returning expired entries; physical cleanup follows its maintenance cycle. Configuration is applied when each plugin cache is created.
Validation:
New positive/negative selector/rule expiration regression fails with the previous non-expiring map constructor and passes with this fix.
./mvnw -B -ntp -pl shenyu-plugin/shenyu-plugin-base -am test -Djacoco.skip=truepasses (11-module reactor, including existing match and invalidation tests)../mvnw -B -ntp checkstyle:checkpasses across 213 modules.Related reactor
apache-rat:checkpasses in a clean source export with the patch. The original checkout's RAT check only flags three pre-existing untracked.omxfiles.git diff --checkpasses. No performance benchmark or full-repository clean install was run.I have read the contribution guidelines.
Tests back the changes.
Full
./mvnw clean install -Dmaven.javadoc.skip=true(targeted reactor tests and full Checkstyle used instead).