1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- // 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_err=break -nullcache=&v1.VideoBase{Svid:-1} -check_null_code=$==nil||$.Svid==-1
- VideoBase(c context.Context, svid []int64) (map[int64]*v1.VideoBase, error)
- }
- */
- package dao
- import (
- "context"
- "go-common/app/service/bbq/video/api/grpc/v1"
- "go-common/library/stat/prom"
- )
- var _ _cache
- // VideoBase get data from cache if miss will call source method, then add to cache.
- func (d *Dao) VideoBase(c context.Context, keys []int64) (res map[int64]*v1.VideoBase, err error) {
- if len(keys) == 0 {
- return
- }
- addCache := true
- if res, err = d.CacheVideoBase(c, keys); 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("VideoBase", int64(len(keys)-len(miss)))
- for k, v := range res {
- if v == nil || v.Svid == -1 {
- delete(res, k)
- }
- }
- missLen := len(miss)
- if missLen == 0 {
- return
- }
- var missData map[int64]*v1.VideoBase
- prom.CacheMiss.Add("VideoBase", int64(len(miss)))
- missData, err = d.RawVideoBase(c, miss)
- if res == nil {
- res = make(map[int64]*v1.VideoBase, len(keys))
- }
- for k, v := range missData {
- res[k] = v
- }
- if err != nil {
- return
- }
- for _, key := range miss {
- if res[key] == nil {
- missData[key] = &v1.VideoBase{Svid: -1}
- }
- }
- if !addCache {
- return
- }
- d.cache.Do(c, func(c context.Context) {
- d.AddCacheVideoBase(c, missData)
- })
- return
- }
|