cache.go 975 B

123456789101112131415161718192021222324252627282930313233343536
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "go-common/app/service/main/passport-game/model"
  8. "go-common/library/log"
  9. )
  10. // TokenPBCache get token pb cache.
  11. func (d *Dao) TokenPBCache(c context.Context, key string) (res *model.Perm, err error) {
  12. if !strings.HasPrefix(key, _keyPrefixTokenPB) {
  13. err = fmt.Errorf("invalid cache key %s, key pattern is %s{token}", key, _keyPrefixInfoPB)
  14. return
  15. }
  16. token := key[len(_keyPrefixTokenPB):]
  17. return d.TokenCache(c, token)
  18. }
  19. // InfoPBCache get info pb cache.
  20. func (d *Dao) InfoPBCache(c context.Context, key string) (res *model.Info, err error) {
  21. if !strings.HasPrefix(key, _keyPrefixInfoPB) {
  22. err = fmt.Errorf("invalid cache key %s, key pattern is %s{mid}", key, _keyPrefixInfoPB)
  23. return
  24. }
  25. midStr := key[len(_keyPrefixInfoPB):]
  26. mid, err := strconv.ParseInt(midStr, 10, 64)
  27. if err != nil {
  28. log.Error("strconv.ParseInt(%s, 10, 64) error(%v)", midStr, err)
  29. return
  30. }
  31. return d.InfoCache(c, mid)
  32. }