From 9688910acfbef1322f4c8def8f556d5f9119e4db Mon Sep 17 00:00:00 2001 From: DavidHLP Date: Sun, 20 Sep 2026 00:22:13 +0800 Subject: [PATCH 1/3] refactor(cache): collapse loader orchestrator onto bound constructor entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 3-arg unbound constructor and the 7-arg per-call callback entry only existed to serve the old test wiring protocol; production RedisProCache already binds the three callbacks at construction. Delete both shallow entries, validate the required callbacks with Objects.requireNonNull at construction (assembly errors now fail at construction, not per call), and have executeSyncLoad/executeLoad read the bound final fields so all loader behavior flows through the single 4-arg orchestrate seam. Migrate every LoaderOrchestratorTest case onto the same constructor-bound path the production adapter uses, preserving the bloom / sync / hit / null / loader-failure / write-back-tolerance assertions, and add the constructor-validation, cross-call no-state, and null-value-wrapper-hit cases required by the accepted design (L01-L10, §2.5). --- .../cache/redis/cache/LoaderOrchestrator.java | 103 ++---- .../redis/cache/LoaderOrchestratorTest.java | 332 ++++++++++-------- 2 files changed, 205 insertions(+), 230 deletions(-) diff --git a/src/main/java/io/github/davidhlp/spring/cache/redis/cache/LoaderOrchestrator.java b/src/main/java/io/github/davidhlp/spring/cache/redis/cache/LoaderOrchestrator.java index 65f63a2e..132d744d 100644 --- a/src/main/java/io/github/davidhlp/spring/cache/redis/cache/LoaderOrchestrator.java +++ b/src/main/java/io/github/davidhlp/spring/cache/redis/cache/LoaderOrchestrator.java @@ -6,6 +6,7 @@ import io.github.davidhlp.spring.cache.redis.chain.model.CachePolicyView; +import java.util.Objects; import java.util.concurrent.Callable; import java.util.function.BiConsumer; import java.util.function.Consumer; @@ -39,15 +40,16 @@ *
  • locality:bloom + sync + load 协议 + 异常翻译规则全部内聚在一处文件, * 无需在 {@code RedisProCache} 与若干 seam 间跳转
  • *
  • testability:orchestrator 仅依赖 {@link BloomGate} / {@link SyncSupport} / - * {@link SyncLockTimeout} + 3 个 callback(redisKey / doubleCheck / putAfterLoad); + * {@link SyncLockTimeout} + 3 个构造期绑定的 callback(redisKey / doubleCheck / putAfterLoad); * 单测可零 RedisProCache fixture 验证决策分支({@code BloomShortCircuited} / * {@code Loaded} / {@code LoadedWithWriteBackFailure} / {@code LoadFailed})
  • *
  • leverage:{@code RedisProCache.get(key, loader)} 主体仅 1 行委派 + switch 翻译
  • * * *

    callback 协议:orchestrator 不继承 {@code RedisCache},因此需要 cache-specific 操作 - * (key 派生 / 双检 / 写回)以 callback 形式由 {@code RedisProCache} 注入;writer 入口则直接 - * 使用静态 {@link #readThrough} 并传入字节适配: + * (key 派生 / 双检 / 写回)以 callback 形式在构造期由 {@code RedisProCache} 绑定;三个 callback + * 均为必需,缺失属于装配错误,构造时用 {@link Objects#requireNonNull} 带参数名拒绝。 + * writer 入口不构造本类,直接使用静态 {@link #readThrough} 并传入字节适配: *