cache.go 415 B

12345678910111213141516171819202122
  1. package utils
  2. import (
  3. "github.com/gogf/gcache-adapter/adapter"
  4. "github.com/gogf/gf/frame/g"
  5. "github.com/gogf/gf/os/gcache"
  6. )
  7. // Cache 自定义缓存服务类
  8. //使用方式
  9. var Cache = CacheService{}
  10. type CacheService struct {
  11. }
  12. func (c CacheService) New() *gcache.Cache {
  13. //配置缓存
  14. cache := gcache.New()
  15. myAdapter := adapter.NewRedis(g.Redis("cache"))
  16. cache.SetAdapter(myAdapter)
  17. return cache
  18. }