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.
94 lines
2.2 KiB
94 lines
2.2 KiB
// 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=[]*arcMdl.Staff{{ID:-1}} -check_null_code=len($)==1&&$[0].ID==-1 |
|
StaffData(c context.Context, aid int64) ([]*arcMdl.Staff, error) |
|
ViewPoint(c context.Context, aid int64, cid int64) (vp *arcMdl.ViewPointRow, err error) |
|
} |
|
*/ |
|
|
|
package archive |
|
|
|
import ( |
|
"context" |
|
|
|
arcMdl "go-common/app/interface/main/creative/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 []*arcMdl.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.RawStaffData(c, id) |
|
return |
|
}) |
|
res = rr.([]*arcMdl.Staff) |
|
if err != nil { |
|
return |
|
} |
|
miss := res |
|
if len(miss) == 0 { |
|
miss = []*arcMdl.Staff{{ID: -1}} |
|
} |
|
if !addCache { |
|
return |
|
} |
|
d.cache.Do(c, func(c context.Context) { |
|
d.AddCacheStaffData(metadata.WithContext(c), id, miss) |
|
}) |
|
return |
|
} |
|
|
|
// ViewPoint cache: -singleflight=true -nullcache=[]*arcMdl.Staff{{ID:-1}} -check_null_code=len($)==1&&$[0].ID==-1 |
|
func (d *Dao) ViewPoint(c context.Context, id int64, cid int64) (res *arcMdl.ViewPointRow, err error) { |
|
addCache := true |
|
res, err = d.CacheViewPoint(c, id, cid) |
|
if err != nil { |
|
addCache = false |
|
err = nil |
|
} |
|
if res != nil { |
|
prom.CacheHit.Incr("ViewPoint") |
|
return |
|
} |
|
prom.CacheMiss.Incr("ViewPoint") |
|
res, err = d.RawViewPoint(c, id, cid) |
|
if err != nil { |
|
return |
|
} |
|
miss := res |
|
if !addCache { |
|
return |
|
} |
|
d.cache.Do(c, func(c context.Context) { |
|
d.AddCacheViewPoint(metadata.WithContext(c), id, miss, cid) |
|
}) |
|
return |
|
}
|
|
|