## Problem 高频接口每次请求都查询数据库: - 单词列表 (`/api/words?bookId=`) — 词书数据基本不变 - 学习统计 (`/api/stats/overview`) — 可按 userId 缓存短时 - 词书进度 (`/api/books/progress`) — 频繁更新但可短期缓存 ## Proposed Solution 1. 引入 Spring Cache + Redis: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> ``` 2. 缓存策略: - `words` — 按 `bookId` 缓存,TTL 1 小时,词书更新时失效 - `stats` — 按 `userId` 缓存,TTL 5 分钟 - `books` — 按 `userId` 缓存,TTL 10 分钟,学习记录写入时部分失效 3. Docker Compose 中增加 Redis 容器
Problem
高频接口每次请求都查询数据库:
/api/words?bookId=) — 词书数据基本不变/api/stats/overview) — 可按 userId 缓存短时/api/books/progress) — 频繁更新但可短期缓存Proposed Solution
缓存策略:
words— 按bookId缓存,TTL 1 小时,词书更新时失效stats— 按userId缓存,TTL 5 分钟books— 按userId缓存,TTL 10 分钟,学习记录写入时部分失效Docker Compose 中增加 Redis 容器