api.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package cache
  2. import "fmt"
  3. func GetCache(myId string) (interface{}, bool) {
  4. return myCache.getCache(myId)
  5. }
  6. func SetCache(myId string, myVal interface{}) {
  7. myCache.setCache(myId, myVal)
  8. }
  9. func SetCacheTimeout(myId string, myVal interface{}, timeout int64) {
  10. myCache.setCacheTimeout(myId, myVal, timeout)
  11. }
  12. func DelCache(myId string) {
  13. myCache.delCache(myId)
  14. }
  15. func SetToken(userId int, token string) {
  16. myCache.setCache(fmt.Sprintf("token_%d", userId), token)
  17. }
  18. func GetToken(userId int) string {
  19. cacheId := fmt.Sprintf("token_%d", userId)
  20. if val, flag := myCache.getCache(cacheId); flag {
  21. return val.(string)
  22. }
  23. return ""
  24. }
  25. func SetPayOk(outTradeBo string) {
  26. myCache.setCache(fmt.Sprintf("pay_%s", outTradeBo), true)
  27. }
  28. func IsPayOk(outTradeBo string) bool {
  29. if _, flag := myCache.getCache(fmt.Sprintf("pay_%s", outTradeBo)); flag {
  30. return true
  31. }
  32. return false
  33. }
  34. func SetPhoneCode(phone, code string) {
  35. myCache.setCacheTimeout(fmt.Sprintf("phone_%s", phone), code, 300)
  36. }
  37. func GetPhoneCode(phone string) string {
  38. cacheId := fmt.Sprintf("phone_%s", phone)
  39. if val, flag := myCache.getCache(cacheId); flag {
  40. return val.(string)
  41. }
  42. return "637901"
  43. }