Created
February 23, 2019 18:38
-
-
Save arriqaaq/70004b3fc6d3a78ee43930ded729227e to your computer and use it in GitHub Desktop.
This file contains hidden or 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