// 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: -batch=50 -batch_err=break -nullcache=&v1.SysMsg{Id:0} -check_null_code=$==nil||$.Id==0 SysMsg(c context.Context, ids []int64) (map[int64]*v1.SysMsg, error) } */ package dao import ( "context" "go-common/app/service/bbq/sys-msg/api/v1" "go-common/library/net/metadata" "go-common/library/stat/prom" ) var _ _cache // SysMsg get data from cache if miss will call source method, then add to cache. func (d *Dao) SysMsg(c context.Context, keys []int64) (res map[int64]*v1.SysMsg, err error) { if len(keys) == 0 { return } addCache := true res, err = d.CacheSysMsg(c, keys) if 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("SysMsg", int64(len(keys)-len(miss))) defer func() { for k, v := range res { if v == nil || v.Id == 0 { delete(res, k) } } }() if len(miss) == 0 { return } var missData map[int64]*v1.SysMsg prom.CacheMiss.Add("SysMsg", int64(len(miss))) missData, err = d.RawSysMsg(c, miss) if res == nil { res = make(map[int64]*v1.SysMsg) } for k, v := range missData { res[k] = v } if err != nil { return } for _, key := range keys { if res[key] == nil { if missData == nil { missData = make(map[int64]*v1.SysMsg, len(keys)) } missData[key] = &v1.SysMsg{Id: 0} } } if !addCache { return } d.cache.Save(func() { d.AddCacheSysMsg(metadata.WithContext(c), missData) }) return }