Created
February 23, 2019 18:40
-
-
Save arriqaaq/d1f688e277474da0e8ab5ff004d65d54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type service struct { | |
storage db.DB | |
logger log.Logger | |
db *sql.DB | |
cache *zizou.Cache | |
} | |
func (s *service) GetEcpm(data getEcpmRequest) (float64, error) { | |
key := NewKey(data.GetCountryId(), data.GetPartner(), data.GetGameId()) | |
icVal, found := s.cache.Get(key.Id()) | |
if found { | |
return icVal.(float64), nil | |
} | |
value, err := s.storage.Get(key.Id()) | |
if err != nil { | |
return 0, err | |
} | |
val, _ := x.ConvertFloat64(value) | |
s.cache.Set(key.Id(), val, 5*time.Minute) | |
return val, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment