Merged
Conversation
## 新增功能
### 1. 本地内存缓存 (Standalone)
- 基于 `github.com/maypok86/otter/v2` 实现
- 支持 Key-Value 操作 (Set/Get/Delete/Has/Expire)
- Hash/ZSet/List 操作返回 "不支持" 错误
- 使用 `ExpiryWriting` 策略,TTL 语义与 Redis 一致
- 默认容量 10000,可配置
### 2. MessagePack 序列化器
- 实现 `MessagePackSerializer`
- 相比 JSON:序列化快 2-3 倍,数据体积小 20-30%
- 新增 `NewMessagePack()` 便捷构造函数
### 3. 统一配置入口
- `New(cfg)` 根据 `cfg.Mode` 选择模式
- `NewStandalone()` 创建本地缓存
- `NewWithRedis()` 创建 Redis 缓存(兼容旧版)
## 配置示例
```go
// 本地缓存
cache.NewStandalone(&cache.StandaloneConfig{Capacity: 10000})
// Redis 缓存
cache.NewWithRedis(conn, &cache.Config{
Prefix: "app:",
Serializer: "msgpack", // 新增
})
// 统一配置
cache.New(&cache.Config{
Mode: "standalone",
Standalone: &cache.StandaloneConfig{Capacity: 5000},
})
```
Closes #29
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
为
cache组件添加本地内存缓存版本(Standalone)和 MessagePack 序列化器支持,参考ratelimit的设计模式。变更内容
1. 本地内存缓存 (cache/standalone.go)
基于高性能缓存库 otter v2 实现:
ErrNotSupportedErrNotSupportedErrNotSupported关键设计:
ExpiryWriting策略,TTL 语义与 Redis 一致(读取不重置过期时间)2. MessagePack 序列化器
新增
MessagePackSerializer:3. 统一配置入口 (cache/cache.go)
使用场景
StandaloneDistributedStandalone(无外部依赖)测试
所有测试通过:
go test -v ./cache/... -run Standalone PASS: TestCache_Standalone (1.00s)Closes #29
🤖 Generated with Claude Code