refactor(cache): 抽离 Redis 缓存初始化逻辑
- 新增 utility/cache.go 文件,定义全局的 RedisCache 变量 - 修改 hero.go 中的缓存使用方式,使用新的 RedisCache 全局变量 - 更新 main.go,移除冗余的包引用
This commit is contained in:
12
utility/cache.go
Normal file
12
utility/cache.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package utility
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcache"
|
||||
)
|
||||
|
||||
var RedisCache = func() *gcache.Cache {
|
||||
cache := gcache.New()
|
||||
cache.SetAdapter(gcache.NewAdapterRedis(g.Redis()))
|
||||
return cache
|
||||
}()
|
||||
Reference in New Issue
Block a user