// Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT. /* Package archive is a generated cache proxy package. It is generated from: type _cache interface { // cache: -singleflight=true -nullcache=[]*archive.Staff{{ID:-1}} -check_null_code=len($)==1&&$[0].ID==-1 StaffData(c context.Context, aid int64) ([]*archive.Staff, error) } */ package archive import ( "context" "go-common/app/service/main/videoup/model/archive" "go-common/library/net/metadata" "go-common/library/stat/prom" "golang.org/x/sync/singleflight" ) var _ _cache var cacheSingleFlights = [1]*singleflight.Group{{}} // StaffData get data from cache if miss will call source method, then add to cache. func (d *Dao) StaffData(c context.Context, id int64) (res []*archive.Staff, err error) { addCache := true res, err = d.CacheStaffData(c, id) if err != nil { addCache = false err = nil } defer func() { if len(res) == 1 && res[0].ID == -1 { res = nil } }() if len(res) != 0 { prom.CacheHit.Incr("StaffData") return } var rr interface{} sf := d.cacheSFStaffData(id) rr, err, _ = cacheSingleFlights[0].Do(sf, func() (r interface{}, e error) { prom.CacheMiss.Incr("StaffData") r, e = d.Staffs(c, id) return }) res = rr.([]*archive.Staff) if err != nil { return } miss := res if len(miss) == 0 { miss = []*archive.Staff{{ID: -1}} } if !addCache { return } d.cache.Do(c, func(ctx context.Context) { d.AddCacheStaffData(metadata.WithContext(c), id, miss) }) return }