// 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.Order{ID:-1} -check_null_code=$!=nil&&$.ID==-1 OrderUser(c context.Context, id int64) (*model.Order, error) // cache: -nullcache=&model.Asset{ID:-1} -check_null_code=$!=nil&&$.ID==-1 -singleflight=true Asset(c context.Context, oid int64, otype string, currency string) (*model.Asset, error) // cache: -nullcache=&model.AggrIncomeUser{Total:-1} -check_null_code=$!=nil&&$.Total==-1 AggrIncomeUser(c context.Context, mid int64) (*model.AggrIncomeUser, error) // cache: -nullcache=&model.AggrIncomeUserMonthly{TotalPayTimes:-1} -check_null_code=$!=nil&&$.TotalPayTimes==-1 AggrIncomeUserMonthly(c context.Context, mid int64, ver string) (*model.AggrIncomeUserMonthly, error) } */ package dao import ( "context" "go-common/app/service/main/ugcpay/model" "go-common/library/net/metadata" "go-common/library/stat/prom" "golang.org/x/sync/singleflight" ) var _ _cache var cacheSingleFlights = [1]*singleflight.Group{{}} // OrderUser get data from cache if miss will call source method, then add to cache. func (d *Dao) OrderUser(c context.Context, id string) (res *model.Order, err error) { addCache := true res, err = d.CacheOrderUser(c, id) if err != nil { addCache = false err = nil } defer func() { if res != nil && res.ID == -1 { res = nil } }() if res != nil { prom.CacheHit.Incr("OrderUser") return } prom.CacheMiss.Incr("OrderUser") res, err = d.RawOrderUser(c, id) if err != nil { return } miss := res if miss == nil { miss = &model.Order{ID: -1} } if !addCache { return } d.cache.Save(func() { d.AddCacheOrderUser(metadata.WithContext(c), id, miss) }) return } // Asset get data from cache if miss will call source method, then add to cache. func (d *Dao) Asset(c context.Context, id int64, otype string, currency string) (res *model.Asset, err error) { addCache := true res, err = d.CacheAsset(c, id, otype, currency) if err != nil { addCache = false err = nil } defer func() { if res != nil && res.ID == -1 { res = nil } }() if res != nil { prom.CacheHit.Incr("Asset") return } var rr interface{} sf := d.cacheSFAsset(id, otype, currency) rr, err, _ = cacheSingleFlights[0].Do(sf, func() (r interface{}, e error) { prom.CacheMiss.Incr("Asset") r, e = d.RawAsset(c, id, otype, currency) return }) res = rr.(*model.Asset) if err != nil { return } miss := res if miss == nil { miss = &model.Asset{ID: -1} } if !addCache { return } d.cache.Save(func() { d.AddCacheAsset(metadata.WithContext(c), id, otype, currency, miss) }) return } // // AggrIncomeUser get data from cache if miss will call source method, then add to cache. // func (d *Dao) AggrIncomeUser(c context.Context, mid int64, currency string) (res *model.AggrIncomeUser, err error) { // addCache := true // res, err = d.CacheAggrIncomeUser(c, mid, currency) // if err != nil { // addCache = false // err = nil // } // defer func() { // if res != nil && res.MID == -1 { // res = nil // } // }() // if res != nil { // prom.CacheHit.Incr("AggrIncomeUser") // return // } // prom.CacheMiss.Incr("AggrIncomeUser") // res, err = d.RawAggrIncomeUser(c, mid, currency) // if err != nil { // return // } // miss := res // if miss == nil { // miss = &model.AggrIncomeUser{MID: -1} // } // if !addCache { // return // } // d.cache.Save(func() { // d.AddCacheAggrIncomeUser(metadata.WithContext(c), mid, currency, miss) // }) // return // } // // AggrIncomeUseAssetList get data from cache if miss will call source method, then add to cache. // func (d *Dao) AggrIncomeUseAssetList(c context.Context, mid int64, currency string, ver int64) (res []*model.AggrIncomeUserAsset, err error) { // addCache := true // res, err = d.CacheAggrIncomeUserAssetList(c, mid, currency, ver) // if err != nil { // addCache = false // err = nil // } // defer func() { // if res != nil && len(res) == 0 { // res = nil // } // }() // if res != nil { // prom.CacheHit.Incr("AggrIncomeUseAssetList") // return // } // prom.CacheMiss.Incr("AggrIncomeUseAssetList") // res, err = d.RawAggrIncomeUserAssetList(c, mid, currency, ver) // if err != nil { // return // } // miss := res // if miss == nil { // miss = make([]*model.AggrIncomeUserAsset, 0) // } // if !addCache { // return // } // d.cache.Save(func() { // d.AddCacheAggrIncomeUserAssetList(metadata.WithContext(c), mid, currency, ver, miss) // }) // return // }