Files
appks/docs/adr/002-two-tier-caching.md
T
zhenyi 1000f8a80d chore(infra): add gRPC layer, update protobufs, remove immediate module
- Add gRPC service modules: auth, channel, channel settings, member,
  permission
- Update protobuf definitions and generated code
- Remove immediate/ real-time module (superseded by IM service)
- Update etcd discovery and registration
- Update cache, error, config, and build infrastructure
- Add ADR documentation
- Update OpenAPI spec
2026-06-10 18:49:42 +08:00

1.4 KiB
Raw Blame History

ADR-002: 两级缓存架构 / Two-Tier Caching Architecture

状态 / Status

Accepted

日期 / Date: 2024-01-01

背景 / Context

平台需要缓存机制来减少数据库负载,提高响应速度。需要在性能和一致性之间取得平衡。

The platform needs a caching mechanism to reduce database load and improve response times. A balance between performance and consistency is required.

决策 / Decision

采用 两级缓存架构L1 (内存 LRU-TTL) + L2 (Redis)。

Adopted two-tier caching: L1 (in-memory LRU-TTL) + L2 (Redis).

考虑的方案 / Considered Options

  1. 纯 Redis — 简单但网络延迟高
  2. 纯内存缓存 — 快但不跨实例共享
  3. 两级缓存 — 兼顾速度和共享

后果 / Consequences

正面 / Positive

  • L1 提供极低延迟 / L1 provides ultra-low latency
  • L2 提供跨实例共享 / L2 provides cross-instance sharing
  • 减少数据库负载 / Reduces database load

负面 / Negative

  • 缓存一致性复杂 / Cache consistency is complex
  • 内存占用增加 / Increased memory usage

风险 / Risks

  • 缓存雪崩 / Cache avalanche
  • 缓存穿透 / Cache penetration

实现细节 / Implementation Details

  • L1: DashMap + Mutex<LruTracker>, TTL 5 分钟
  • L2: Redis via r2d2, TTL 可配置
  • 策略: L1 miss → L2 miss → 数据库查询