cache.go 744 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * @desc:缓存处理
  3. * @company:云南奇讯科技有限公司
  4. * @Author: yixiaohu
  5. * @Date: 2022/3/9 11:15
  6. */
  7. package service
  8. import (
  9. "context"
  10. "github.com/gogf/gf/v2/frame/g"
  11. "github.com/tiger1103/gfast-cache/cache"
  12. "github.com/tiger1103/gfast/v3/internal/app/common/consts"
  13. )
  14. type ICache interface {
  15. cache.IGCache
  16. }
  17. type cacheImpl struct {
  18. *cache.GfCache
  19. prefix string
  20. }
  21. var c = cacheImpl{}
  22. func Cache(ctx context.Context) ICache {
  23. ch := c
  24. prefix := g.Cfg().MustGet(ctx, "system.cache.prefix").String()
  25. model := g.Cfg().MustGet(ctx, "system.cache.model").String()
  26. if model == consts.CacheModelRedis {
  27. // redis
  28. ch.GfCache = cache.NewRedis(prefix)
  29. } else {
  30. ch.GfCache = cache.New(prefix)
  31. }
  32. return ICache(&ch)
  33. }