go-common/app/interface/main/esports/dao/dao.cache.go
2019-04-22 18:49:16 +08:00

157 lines
3.5 KiB
Go

// Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
/*
Package dao is a generated cache proxy package.
It is generated from:
type _cache interface {
// cache
EpContests(c context.Context, ids []int64) (map[int64]*model.Contest, error)
// cache
EpSeasons(c context.Context, ids []int64) (map[int64]*model.Season, error)
// cache
EpTeams(c context.Context, ids []int64) (map[int64]*model.Team, error)
// cache
EpContestsData(c context.Context, ids []int64) (map[int64][]*model.ContestsData, error)
}
*/
package dao
import (
"context"
"go-common/app/interface/main/esports/model"
"go-common/library/stat/prom"
)
var _ _cache
// EpContests get data from cache if miss will call source method, then add to cache.
func (d *Dao) EpContests(c context.Context, keys []int64) (res map[int64]*model.Contest, err error) {
if len(keys) == 0 {
return
}
addCache := true
if res, err = d.CacheEpContests(c, keys); err != nil {
addCache = false
res = nil
err = nil
}
var miss []int64
for _, key := range keys {
if (res == nil) || (res[key] == nil) {
miss = append(miss, key)
}
}
prom.CacheHit.Add("EpContests", int64(len(keys)-len(miss)))
missLen := len(miss)
if missLen == 0 {
return
}
var missData map[int64]*model.Contest
prom.CacheMiss.Add("EpContests", int64(len(miss)))
missData, err = d.RawEpContests(c, miss)
if res == nil {
res = make(map[int64]*model.Contest, len(keys))
}
for k, v := range missData {
res[k] = v
}
if err != nil {
return
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheEpContests(c, missData)
})
return
}
// EpSeasons get data from cache if miss will call source method, then add to cache.
func (d *Dao) EpSeasons(c context.Context, keys []int64) (res map[int64]*model.Season, err error) {
if len(keys) == 0 {
return
}
addCache := true
if res, err = d.CacheEpSeasons(c, keys); err != nil {
addCache = false
res = nil
err = nil
}
var miss []int64
for _, key := range keys {
if (res == nil) || (res[key] == nil) {
miss = append(miss, key)
}
}
prom.CacheHit.Add("EpSeasons", int64(len(keys)-len(miss)))
missLen := len(miss)
if missLen == 0 {
return
}
var missData map[int64]*model.Season
prom.CacheMiss.Add("EpSeasons", int64(len(miss)))
missData, err = d.RawEpSeasons(c, miss)
if res == nil {
res = make(map[int64]*model.Season, len(keys))
}
for k, v := range missData {
res[k] = v
}
if err != nil {
return
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheEpSeasons(c, missData)
})
return
}
// EpTeams get data from cache if miss will call source method, then add to cache.
func (d *Dao) EpTeams(c context.Context, keys []int64) (res map[int64]*model.Team, err error) {
if len(keys) == 0 {
return
}
addCache := true
if res, err = d.CacheEpTeams(c, keys); err != nil {
addCache = false
res = nil
err = nil
}
var miss []int64
for _, key := range keys {
if (res == nil) || (res[key] == nil) {
miss = append(miss, key)
}
}
prom.CacheHit.Add("EpTeams", int64(len(keys)-len(miss)))
missLen := len(miss)
if missLen == 0 {
return
}
var missData map[int64]*model.Team
prom.CacheMiss.Add("EpTeams", int64(len(miss)))
missData, err = d.RawEpTeams(c, miss)
if res == nil {
res = make(map[int64]*model.Team, len(keys))
}
for k, v := range missData {
res[k] = v
}
if err != nil {
return
}
if !addCache {
return
}
d.cache.Do(c, func(c context.Context) {
d.AddCacheEpTeams(c, missData)
})
return
}