123456789101112131415161718192021222324252627282930313233 |
- package config
- import (
- "gogs.baozhida.cn/zoie/OAuth-core/storage"
- "gogs.baozhida.cn/zoie/OAuth-core/storage/cache"
- )
- type Cache struct {
- Redis *RedisConnectOptions
- Memory interface{}
- }
- // CacheConfig cache配置
- var CacheConfig = new(Cache)
- // Setup 构造cache 顺序 redis > 其他 > memory
- func (e Cache) Setup() (storage.AdapterCache, error) {
- if e.Redis != nil {
- options, err := e.Redis.GetRedisOptions()
- if err != nil {
- return nil, err
- }
- r, err := cache.NewRedis(GetRedisClient(), options)
- if err != nil {
- return nil, err
- }
- if _redis == nil {
- _redis = r.GetClient()
- }
- return r, nil
- }
- return cache.NewMemory(), nil
- }
|