2 Star 0 Fork 0

djienet/kratos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
none_template.go 1.32 KB
一键复制 编辑 原始数据 按行查看 历史
chenli 提交于 2020-11-02 15:31 +08:00 . init
package main
var _noneTemplate = `
// NAME {{or .Comment "get data from cache if miss will call source method, then add to cache."}}
func (d *{{.StructName}}) NAME(c context.Context) (res VALUE, err error) {
addCache := true
res, err = CACHEFUNC(c)
if err != nil {
{{if .CacheErrContinue}}
addCache = false
err = nil
{{else}}
return
{{end}}
}
{{if .EnableNullCache}}
defer func() {
{{if .SimpleValue}} if res == {{.NullCache}} { {{else}} if {{.CheckNullCode}} { {{end}}
res = {{.ZeroValue}}
}
}()
{{end}}
{{if .GoValue}}
if len(res) != 0 {
{{else}}
if res != {{.ZeroValue}} {
{{end}}
cache.MetricHits.Inc("bts:NAME")
return
}
{{if .EnableSingleFlight}}
var rr interface{}
sf := d.cacheSFNAME()
rr, err, _ = cacheSingleFlights[SFNUM].Do(sf, func() (r interface{}, e error) {
cache.MetricMisses.Inc("bts:NAME")
r, e = RAWFUNC(c)
return
})
res = rr.(VALUE)
{{else}}
cache.MetricMisses.Inc("bts:NAME")
res, err = RAWFUNC(c)
{{end}}
if err != nil {
return
}
var miss = res
{{if .EnableNullCache}}
{{if .GoValue}}
if len(miss) == 0 {
{{else}}
if miss == {{.ZeroValue}} {
{{end}}
miss = {{.NullCache}}
}
{{end}}
if !addCache {
return
}
{{if .Sync}}
ADDCACHEFUNC(c, miss)
{{else}}
d.cache.Do(c, func(c context.Context) {
ADDCACHEFUNC(c, miss)
})
{{end}}
return
}
`
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/djienet/kratos.git
git@gitee.com:djienet/kratos.git
djienet
kratos
kratos
v1.1.7

搜索帮助