hanzhe-one opened a new pull request, #7849:
URL: https://github.com/apache/shenyu/pull/7849

   Fixes #7828
   
   ### Problem
   
   `MemoryCache` is a local Caffeine cache, but every read wrapped the lookup in
   `Mono.fromCallable(...).subscribeOn(Schedulers.boundedElastic())`, so a 
cache hit queued a task on the
   bounded-elastic pool even though the work was a local map read. `cacheData` 
scheduled an
   already-computed `Boolean.TRUE` the same way.
   
   The issue was reported against a revision that predates #7745 (merged at 
2026-10-19T01:29Z), which
   replaced the Guava implementation with Caffeine and already removed the 
duplicate
   existence-check-then-read path. This PR therefore covers the remaining part 
of the task: the
   scheduler hand-off.
   
   ### Change
   
   - `cacheData`: return `Mono.just(Boolean.TRUE)` — the write already happened 
eagerly.
   - `isExist` / `getData`: drop `subscribeOn(Schedulers.boundedElastic())`. 
The lookup stays lazy at
     subscription time (`Mono.fromCallable`), so hit/miss, per-entry TTL and 
replacement semantics are
     unchanged; only the thread the lookup runs on differs. Callers that need a 
different thread can
     still apply their own `subscribeOn`.
   
   ### Deliberately out of scope
   
   - `CachePlugin.cacheResponse` applies its own 
`subscribeOn(Schedulers.boundedElastic())` for the
     write path. That is backend-agnostic and affects Redis too, so it is left 
untouched here.
   - Removing the hop moves `CachedResponse.decode` (header JSON parse + body 
copy, chained in
     `CachePlugin.executeCache`) onto the subscribing thread, which is the 
Netty event loop in the
     gateway. No throughput claim is made for this change; no JMH benchmark 
exists in this repository
     and none was run.
   
   ### Tests
   
   - `testReadsRunOnTheSubscribingThread` subscribes `isExist`/`getData` on a 
named single scheduler and
     asserts the lookup runs on that scheduler. Verified to fail with the 
previous implementation
     (`boundedElastic-1`) and pass with this one.
   - `testReadsAreDeferredUntilSubscription` asserts `getData` does not observe 
the cache at assembly
     time.
   - `./mvnw -pl shenyu-plugin/shenyu-plugin-cache/shenyu-plugin-cache-memory 
-am test` — BUILD SUCCESS,
     checkstyle clean.
   - `./mvnw -pl shenyu-plugin/shenyu-plugin-cache/shenyu-plugin-cache-handler 
-am test -Dtest='org.apache.shenyu.plugin.cache.**'`
     — 97 tests, BUILD SUCCESS.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to