Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Created February 23, 2019 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arriqaaq/d1f688e277474da0e8ab5ff004d65d54 to your computer and use it in GitHub Desktop.
Save arriqaaq/d1f688e277474da0e8ab5ff004d65d54 to your computer and use it in GitHub Desktop.
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