cache.go 777 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * @desc:缓存处理
  3. * @company:云南奇讯科技有限公司
  4. * @Author: yixiaohu
  5. * @Date: 2022/3/9 11:15
  6. */
  7. package service
  8. import (
  9. "github.com/gogf/gf/v2/frame/g"
  10. "github.com/gogf/gf/v2/os/gctx"
  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() ICache {
  23. var (
  24. ch = c
  25. ctx = gctx.New()
  26. )
  27. prefix := g.Cfg().MustGet(ctx, "system.cache.prefix").String()
  28. model := g.Cfg().MustGet(ctx, "system.cache.model").String()
  29. if model == consts.CacheModelRedis {
  30. // redis
  31. ch.GfCache = cache.NewRedis(prefix)
  32. } else {
  33. ch.GfCache = cache.New(prefix)
  34. }
  35. return ICache(&ch)
  36. }