Ai
1 Star 0 Fork 1

Bin/gotemplate

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
parse_cache.go 487 Bytes
一键复制 编辑 原始数据 按行查看 历史
YouBin 提交于 2025-02-25 12:44 +08:00 . 增加sqlrender的支持
package gotemplate
import "sync"
type parsedCache struct {
sync.RWMutex
cache map[string]string
}
func (c *parsedCache) GetIfNotExist(key string, fn func() string) string {
res := (func() string {
c.RLock()
defer c.RUnlock()
if value, ok := c.cache[key]; ok {
return value
}
return ""
})()
if res != "" {
return res
}
c.Lock()
defer c.Unlock()
// double check
if value, ok := c.cache[key]; ok {
return value
}
res = fn()
c.cache[key] = res
return res
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/llyb120/gotemplate.git
git@gitee.com:llyb120/gotemplate.git
llyb120
gotemplate
gotemplate
master

搜索帮助