https://github.com/glidea/gcache
mini distributed cache
https://github.com/glidea/gcache
Last synced: about 1 year ago
JSON representation
mini distributed cache
- Host: GitHub
- URL: https://github.com/glidea/gcache
- Owner: glidea
- Created: 2021-10-05T14:30:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-06T01:58:55.000Z (over 4 years ago)
- Last Synced: 2024-09-13T15:57:52.610Z (almost 2 years ago)
- Language: Go
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
一个分布式缓存框架(仿照 groupcache 实现,当然现在看起来已经没什么关系了)
### 主要特点
* 代码小巧,适合作为学习向的项目
* 易拓展。注册中心、缓存淘汰策略、RPC 协议、数据分片策略均可轻易替换实现
### 快速开始
```go
var (
dbHeight = map[string]string{
"laowang": "173",
"xiaoming": "166",
}
dbScore = map[string]string{
"laowang": "96",
"xiaoming": "97",
}
)
func main() {
c := gcache.New()
c.Group("height", 1<<10, gcache.EvictionLru, time.Minute, gcache.ShardingConsistenthash,
gcache.DBGetterFunc(func(key string) ([]byte, error) {
return []byte(dbHeight[key]), nil
}))
c.Group("score", 1<<10, gcache.EvictionLru, time.Minute, gcache.ShardingConsistenthash,
gcache.DBGetterFunc(func(key string) ([]byte, error) {
return []byte(dbScore[key]), nil
}))
c.Registry(gcache.RegistryZK, "xxxxxxxxx")
c.Protocol(gcache.ProtocolHTTP)
err := c.Start(":6060")
if err != nil {
log.Fatal("server start fail: " + err.Error())
}
}
```