dao.cache.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. // cache: -nullcache=&model.UserInfo{ID:-1} -check_null_code=$.ID==-1
  7. UserInfoByMid(c context.Context, key int64) (*model.UserInfo, error)
  8. }
  9. */
  10. package dao
  11. import (
  12. "context"
  13. "go-common/app/service/main/tv/internal/model"
  14. "go-common/library/stat/prom"
  15. )
  16. var _ _cache
  17. // UserInfoByMid get data from cache if miss will call source method, then add to cache.
  18. func (d *Dao) UserInfoByMid(c context.Context, id int64) (res *model.UserInfo, err error) {
  19. addCache := true
  20. res, err = d.CacheUserInfoByMid(c, id)
  21. if err != nil {
  22. addCache = false
  23. err = nil
  24. }
  25. if res != nil {
  26. prom.CacheHit.Incr("UserInfoByMid")
  27. return
  28. }
  29. prom.CacheMiss.Incr("UserInfoByMid")
  30. res, err = d.RawUserInfoByMid(c, id)
  31. if err != nil {
  32. return
  33. }
  34. miss := res
  35. if miss == nil {
  36. miss = &model.UserInfo{ID: -1}
  37. res = miss
  38. }
  39. if !addCache {
  40. return
  41. }
  42. d.cache.Do(c, func(c context.Context) {
  43. d.AddCacheUserInfoByMid(c, id, miss)
  44. })
  45. return
  46. }