cache.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "time"
  7. )
  8. func countKey(mid int64) string {
  9. return "uct2_" + strconv.FormatInt(mid, 10)
  10. }
  11. func (d *Dao) cacheSFUserCoin(mid int64) string {
  12. return "uct_" + strconv.FormatInt(mid, 10)
  13. }
  14. func itemCoinKey(aid, tp int64) string {
  15. return fmt.Sprintf("itc_%d_%d", tp, aid)
  16. }
  17. func (d *Dao) cacheSFItemCoin(aid int64, tp int64) string {
  18. return fmt.Sprintf("itc_%d_%d", aid, tp)
  19. }
  20. func expKey(mid int64) (key string) {
  21. now := time.Now()
  22. key = fmt.Sprintf("exp_%d_%02d%02d", mid, now.Month(), now.Day())
  23. return
  24. }
  25. //go:generate $GOPATH/src/go-common/app/tool/cache/mc
  26. type _mc interface {
  27. // get user coin count.
  28. // mc: -key=countKey
  29. CacheUserCoin(c context.Context, mid int64) (count float64, err error)
  30. // set user coin count
  31. // mc: -key=countKey -expire=d.mcExpire
  32. AddCacheUserCoin(c context.Context, mid int64, count float64) (err error)
  33. // mc: -key=itemCoinKey
  34. CacheItemCoin(c context.Context, aid int64, tp int64) (count int64, err error)
  35. // mc: -key=itemCoinKey -expire=d.mcExpire
  36. AddCacheItemCoin(c context.Context, aid int64, count int64, tp int64) (err error)
  37. // mc: -key=expKey -type=get
  38. Exp(c context.Context, mid int64) (exp int64, err error)
  39. // mc: -key=expKey -expire=d.expireExp
  40. SetTodayExpCache(c context.Context, mid int64, exp int64) (err error)
  41. }
  42. //go:generate $GOPATH/src/go-common/app/tool/cache/gen
  43. type _cache interface {
  44. // cache: -nullcache=-1 -check_null_code=$==-1 -singleflight=true
  45. UserCoin(c context.Context, mid int64) (count float64, err error)
  46. // cache: -nullcache=-1 -check_null_code=$==-1 -singleflight=true
  47. ItemCoin(c context.Context, aid int64, tp int64) (count int64, err error)
  48. }