dao.cache.go 900 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
  2. /*
  3. Package dao is a generated cache proxy package.
  4. It is generated from:
  5. type _cache interface {
  6. GameList(c context.Context) (res []int64, err error)
  7. }
  8. */
  9. package dao
  10. import (
  11. "context"
  12. "go-common/library/net/metadata"
  13. "go-common/library/stat/prom"
  14. )
  15. var _ _cache
  16. // GameList get data from cache if miss will call source method, then add to cache.
  17. func (d *Dao) GameList(c context.Context) (res []int64, err error) {
  18. addCache := true
  19. res, err = d.CacheGameList(c)
  20. if err != nil {
  21. addCache = false
  22. err = nil
  23. }
  24. if len(res) != 0 {
  25. prom.CacheHit.Incr("GameList")
  26. return
  27. }
  28. prom.CacheMiss.Incr("GameList")
  29. res, err = d.RawGameList(c)
  30. if err != nil {
  31. return
  32. }
  33. var miss = res
  34. if !addCache {
  35. return
  36. }
  37. d.cache.Save(func() {
  38. d.AddCacheGameList(metadata.WithContext(c), miss)
  39. })
  40. return
  41. }