示例#1
0
文件: util.go 项目: jittuu/hivepeek
func FillTeamsCache(c *internal.DSContext) error {
	teams, err := c.GetAllTeams()
	if err != nil {
		return err
	}
	items := make([]*memcache.Item, len(teams))
	for i := range teams {
		key := fmt.Sprintf("teamID:byproviderID:%d", teams[i].ProviderID)
		items[i] = &memcache.Item{
			Key:   key,
			Value: []byte(strconv.FormatInt(teams[i].ID, 10)),
		}
	}

	return memcache.AddMulti(c, items)
}
示例#2
0
文件: util.go 项目: jittuu/hivepeek
func GetLeagueNameByProviderID(c *internal.DSContext, leagueID int) string {
	key := fmt.Sprintf("leaguename:byproviderID:%d", leagueID)
	if item, err := memcache.Get(c, key); err == nil {
		return string(item.Value)
	} else if err == memcache.ErrCacheMiss {
		xleague, _ := c.GetLeagueByProviderID(leagueID)
		if xleague != nil {
			memcache.Set(c, &memcache.Item{
				Key:   key,
				Value: []byte(xleague.Name),
			})

			return xleague.Name
		}
	}
	return ""
}