cache.go 931 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * @desc:缓存处理
  3. * @company:云南奇讯科技有限公司
  4. * @Author: yixiaohu<yxh669@qq.com>
  5. * @Date: 2022/9/27 16:33
  6. */
  7. package cache
  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. "github.com/tiger1103/gfast/v3/internal/app/common/service"
  14. )
  15. func init() {
  16. service.RegisterCache(New())
  17. }
  18. func New() *sCache {
  19. var (
  20. ctx = gctx.New()
  21. cacheContainer *cache.GfCache
  22. )
  23. prefix := g.Cfg().MustGet(ctx, "system.cache.prefix").String()
  24. model := g.Cfg().MustGet(ctx, "system.cache.model").String()
  25. if model == consts.CacheModelRedis {
  26. // redis
  27. cacheContainer = cache.NewRedis(prefix)
  28. } else {
  29. // memory
  30. cacheContainer = cache.New(prefix)
  31. }
  32. return &sCache{
  33. GfCache: cacheContainer,
  34. prefix: prefix,
  35. }
  36. }
  37. type sCache struct {
  38. *cache.GfCache
  39. prefix string
  40. }