205 lines
4.6 KiB
Go
205 lines
4.6 KiB
Go
|
// 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.Notice{Notice:"ff2364a0be3d20e46cc69efb36afe9a5"} -check_null_code=$.Notice=="ff2364a0be3d20e46cc69efb36afe9a5"
|
||
|
Notice(c context.Context, mid int64) (*model.Notice, error)
|
||
|
// cache: -nullcache=&model.AidReason{Aid:-1} -check_null_code=$!=nil&&$.Aid==-1
|
||
|
TopArc(c context.Context, mid int64) (*model.AidReason, error)
|
||
|
// cache: -nullcache=&model.AidReasons{List:[]*model.AidReason{{Aid:-1}}} -check_null_code=len($.List)==1&&$.List[0].Aid==-1
|
||
|
Masterpiece(c context.Context, mid int64) (*model.AidReasons, error)
|
||
|
// cache: -nullcache=&model.ThemeDetails{List:[]*model.ThemeDetail{{ID:-1}}} -check_null_code=len($.List)==1&&$.List[0].ID==-1
|
||
|
Theme(c context.Context, mid int64) (*model.ThemeDetails, error)
|
||
|
// cache: -nullcache=-1 -check_null_code=$==-1
|
||
|
TopDynamic(c context.Context, mid int64) (int64, error)
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
package dao
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"go-common/app/interface/main/space/model"
|
||
|
"go-common/library/stat/prom"
|
||
|
)
|
||
|
|
||
|
var _ _cache
|
||
|
|
||
|
// Notice get data from cache if miss will call source method, then add to cache.
|
||
|
func (d *Dao) Notice(c context.Context, id int64) (res *model.Notice, err error) {
|
||
|
addCache := true
|
||
|
res, err = d.CacheNotice(c, id)
|
||
|
if err != nil {
|
||
|
addCache = false
|
||
|
err = nil
|
||
|
}
|
||
|
defer func() {
|
||
|
if res.Notice == "ff2364a0be3d20e46cc69efb36afe9a5" {
|
||
|
res = nil
|
||
|
}
|
||
|
}()
|
||
|
if res != nil {
|
||
|
prom.CacheHit.Incr("Notice")
|
||
|
return
|
||
|
}
|
||
|
prom.CacheMiss.Incr("Notice")
|
||
|
res, err = d.RawNotice(c, id)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
miss := res
|
||
|
if miss == nil {
|
||
|
miss = &model.Notice{Notice: "ff2364a0be3d20e46cc69efb36afe9a5"}
|
||
|
}
|
||
|
if !addCache {
|
||
|
return
|
||
|
}
|
||
|
d.cache.Do(c, func(c context.Context) {
|
||
|
d.AddCacheNotice(c, id, miss)
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// TopArc get data from cache if miss will call source method, then add to cache.
|
||
|
func (d *Dao) TopArc(c context.Context, id int64) (res *model.AidReason, err error) {
|
||
|
addCache := true
|
||
|
res, err = d.CacheTopArc(c, id)
|
||
|
if err != nil {
|
||
|
addCache = false
|
||
|
err = nil
|
||
|
}
|
||
|
defer func() {
|
||
|
if res != nil && res.Aid == -1 {
|
||
|
res = nil
|
||
|
}
|
||
|
}()
|
||
|
if res != nil {
|
||
|
prom.CacheHit.Incr("TopArc")
|
||
|
return
|
||
|
}
|
||
|
prom.CacheMiss.Incr("TopArc")
|
||
|
res, err = d.RawTopArc(c, id)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
miss := res
|
||
|
if miss == nil {
|
||
|
miss = &model.AidReason{Aid: -1}
|
||
|
}
|
||
|
if !addCache {
|
||
|
return
|
||
|
}
|
||
|
d.cache.Do(c, func(c context.Context) {
|
||
|
d.AddCacheTopArc(c, id, miss)
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// Masterpiece get data from cache if miss will call source method, then add to cache.
|
||
|
func (d *Dao) Masterpiece(c context.Context, id int64) (res *model.AidReasons, err error) {
|
||
|
addCache := true
|
||
|
res, err = d.CacheMasterpiece(c, id)
|
||
|
if err != nil {
|
||
|
addCache = false
|
||
|
err = nil
|
||
|
}
|
||
|
defer func() {
|
||
|
if len(res.List) == 1 && res.List[0].Aid == -1 {
|
||
|
res = nil
|
||
|
}
|
||
|
}()
|
||
|
if res != nil {
|
||
|
prom.CacheHit.Incr("Masterpiece")
|
||
|
return
|
||
|
}
|
||
|
prom.CacheMiss.Incr("Masterpiece")
|
||
|
res, err = d.RawMasterpiece(c, id)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
miss := res
|
||
|
if miss == nil {
|
||
|
miss = &model.AidReasons{List: []*model.AidReason{{Aid: -1}}}
|
||
|
}
|
||
|
if !addCache {
|
||
|
return
|
||
|
}
|
||
|
d.cache.Do(c, func(c context.Context) {
|
||
|
d.AddCacheMasterpiece(c, id, miss)
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// Theme get data from cache if miss will call source method, then add to cache.
|
||
|
func (d *Dao) Theme(c context.Context, id int64) (res *model.ThemeDetails, err error) {
|
||
|
addCache := true
|
||
|
res, err = d.CacheTheme(c, id)
|
||
|
if err != nil {
|
||
|
addCache = false
|
||
|
err = nil
|
||
|
}
|
||
|
defer func() {
|
||
|
if len(res.List) == 1 && res.List[0].ID == -1 {
|
||
|
res = nil
|
||
|
}
|
||
|
}()
|
||
|
if res != nil {
|
||
|
prom.CacheHit.Incr("Theme")
|
||
|
return
|
||
|
}
|
||
|
prom.CacheMiss.Incr("Theme")
|
||
|
res, err = d.RawTheme(c, id)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
miss := res
|
||
|
if miss == nil {
|
||
|
miss = &model.ThemeDetails{List: []*model.ThemeDetail{{ID: -1}}}
|
||
|
}
|
||
|
if !addCache {
|
||
|
return
|
||
|
}
|
||
|
d.cache.Do(c, func(c context.Context) {
|
||
|
d.AddCacheTheme(c, id, miss)
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
// TopDynamic get data from cache if miss will call source method, then add to cache.
|
||
|
func (d *Dao) TopDynamic(c context.Context, id int64) (res int64, err error) {
|
||
|
addCache := true
|
||
|
res, err = d.CacheTopDynamic(c, id)
|
||
|
if err != nil {
|
||
|
addCache = false
|
||
|
err = nil
|
||
|
}
|
||
|
defer func() {
|
||
|
if res == -1 {
|
||
|
res = 0
|
||
|
}
|
||
|
}()
|
||
|
if res != 0 {
|
||
|
prom.CacheHit.Incr("TopDynamic")
|
||
|
return
|
||
|
}
|
||
|
prom.CacheMiss.Incr("TopDynamic")
|
||
|
res, err = d.RawTopDynamic(c, id)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
miss := res
|
||
|
if miss == 0 {
|
||
|
miss = -1
|
||
|
}
|
||
|
if !addCache {
|
||
|
return
|
||
|
}
|
||
|
d.cache.Do(c, func(c context.Context) {
|
||
|
d.AddCacheTopDynamic(c, id, miss)
|
||
|
})
|
||
|
return
|
||
|
}
|