把机制收成引擎:11 机制包 ↔ 章节映射
自研缓存引擎的最小骨架是把机制拆成包、每包对应本卷若干章节。CacheEngine.Skeleton 含 11 个机制包,全部源码在卷二十五实验包
;cache.engine 账本锚定骨架:11 机制包、MAPPING 11 行、覆盖 core/pattern/evict/ring/cluster/coherence/protect/hotspot/store/consistency/ops,lab.RunAll 222 断言全绿。
11 包 ↔ 章节映射
| 包 | 章节 | 核心机制(lab 断言) |
|---|---|---|
| core | 1.x | 缓存局部性、平台数据流 |
| pattern | 2.x | cache-aside 双写、read-through、write-back |
| evict | 3.x | 容量淘汰触发、LRU/LFU/TTL、2Q/ARC |
| ring | 4.x | 一致性哈希 moved=344 |
| cluster | 5.x | 16384 槽、gossip、槽迁移 |
| coherence | 6.x | 失效 4 ops/更新 3 ops、版本 fencing |
| protect | 7.x | 单飞、布隆空值、TTL 抖动 |
| hotspot | 8.x | 热点检测、键拆分、L1+L2 |
| store | 9.x | 哈希表、skiplist、序列化压缩 |
| consistency | 10.x | 双写 60s 窗口、CDC 100→95、对账 |
| ops | 11.x/12.x | 命中账本、容量规划、降级旁路 |
权威值:222 断言全绿
RunAll 依依赖序跑 11 包再跑 lab.IntegrationSuite,MAPPING 11 行把「包 ↔ 章节」钉死;cache.engine 账本断言 222 passed 全绿(ALL GREEN),为唯一权威值。站内卷八一致性哈希/缓存体系、卷七 fencing 只一句话引用;本卷自研骨架只复刻机制,不复刻 Redis/Caffeine 教程,13 章的真实产品对照见13.3 节
。
架构与流程
flowchart LR
A["CacheEngine.Skeleton"] --> B["11 机制包 + IntegrationSuite"]
B --> C["core/pattern/evict/ring/cluster"]
B --> D["coherence/protect/hotspot/store"]
B --> E["consistency/ops"]
A --> F["MAPPING 11 行"]
A --> G["lab.RunAll 222 全绿"]
每个包就是一个可独立断言的最小机制:cache.ring.ConsistentHashRing、cache.coherence.InvalidateOrUpdate、cache.protect.SingleFlight、cache.hotspot.HotKeySplitter、cache.consistency.DualWriteReconciler 等与 15.1 的 6 轴矩阵逐格对应,选一个包就选一态。
实现与验证边界
cache.engine 账本锚定骨架结构:11 机制包、MAPPING 11 行、覆盖 core/pattern/evict/ring/cluster/coherence/protect/hotspot/store/consistency/ops、lab.RunAll 222 断言全绿,为唯一权威值;一致性哈希 2→3 moved=344 由 cache.ring 探针锚定(python 3.12-slim 容器实测,分布式缓存账本模拟)。本机无真实缓存集群,真实吞吐、延迟与一致性协议实机未测,骨架扩到生产(真实 Redis Cluster、Kafka 失效管道、Caffeine 客户端)属模型算术,按「未测工程能力」标注。站内卷八缓存体系、卷七 fencing 只一句话引用,不重写。
一手资料
继续阅读
探索更多技术文章
浏览归档,发现更多关于系统设计、工具链和工程实践的内容。