dao.cache.go 1010 B

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