You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.1 KiB
52 lines
1.1 KiB
// 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: -nullcache=&model.UserInfo{ID:-1} -check_null_code=$.ID==-1 |
|
UserInfoByMid(c context.Context, key int64) (*model.UserInfo, error) |
|
} |
|
*/ |
|
|
|
package dao |
|
|
|
import ( |
|
"context" |
|
|
|
"go-common/app/service/main/tv/internal/model" |
|
"go-common/library/stat/prom" |
|
) |
|
|
|
var _ _cache |
|
|
|
// UserInfoByMid get data from cache if miss will call source method, then add to cache. |
|
func (d *Dao) UserInfoByMid(c context.Context, id int64) (res *model.UserInfo, err error) { |
|
addCache := true |
|
res, err = d.CacheUserInfoByMid(c, id) |
|
if err != nil { |
|
addCache = false |
|
err = nil |
|
} |
|
if res != nil { |
|
prom.CacheHit.Incr("UserInfoByMid") |
|
return |
|
} |
|
prom.CacheMiss.Incr("UserInfoByMid") |
|
res, err = d.RawUserInfoByMid(c, id) |
|
if err != nil { |
|
return |
|
} |
|
miss := res |
|
if miss == nil { |
|
miss = &model.UserInfo{ID: -1} |
|
res = miss |
|
} |
|
if !addCache { |
|
return |
|
} |
|
d.cache.Do(c, func(c context.Context) { |
|
d.AddCacheUserInfoByMid(c, id, miss) |
|
}) |
|
return |
|
}
|
|
|