2021-11-02 09:43:19 +08:00
|
|
|
|
package cache
|
|
|
|
|
|
|
|
|
|
import (
|
2021-11-02 10:02:52 +08:00
|
|
|
|
"ArmedPolice/config"
|
|
|
|
|
"ArmedPolice/serve/cache/logic"
|
2021-11-02 09:43:19 +08:00
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
Cache logic.ICache
|
|
|
|
|
|
|
|
|
|
engines = map[string]func() logic.ICache{
|
|
|
|
|
"memory": memory, "redis": redis,
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func memory() logic.ICache {
|
|
|
|
|
return logic.NewMemory()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func redis() logic.ICache {
|
|
|
|
|
return logic.NewRedis(&logic.RedisOption{
|
|
|
|
|
Addr: config.SettingInfo.Cache.Redis.Addr,
|
|
|
|
|
Password: config.SettingInfo.Cache.Redis.Password,
|
|
|
|
|
DB: config.SettingInfo.Cache.Redis.DB,
|
|
|
|
|
MinIdleConns: config.SettingInfo.Cache.Redis.MaxIdle,
|
|
|
|
|
IdleTimeout: config.SettingInfo.Cache.Redis.IdleTimeout,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Init() {
|
|
|
|
|
handle, has := engines[config.SettingInfo.Cache.Type]
|
|
|
|
|
|
|
|
|
|
if !has {
|
|
|
|
|
panic(fmt.Sprintf("Unknown Cache Engine Mode:%s", config.SettingInfo.Cache.Type))
|
|
|
|
|
}
|
|
|
|
|
Cache = handle()
|
|
|
|
|
|
|
|
|
|
err := Cache.Run()
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic("Cache Run Error:" + err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|