Ai
1 Star 1 Fork 1

xiaoyutab/xgotool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cache.go 592 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaoyutab 提交于 2024-08-19 23:38 +08:00 . https.cache代码优化
package https
import (
"sync"
"time"
)
// 内建缓存组件
type cache struct {
sync.Map
}
// 获取缓存的值
//
// name 缓存名称
func (c *cache) Get(name string) string {
if v, ok := c.Load(name); ok {
if str, ok := v.(string); ok {
return str
}
}
return ""
}
// 设置缓存项的值
//
// name 设置项名称
// val 缓存项的值
// t 缓存时间 -/0-不缓存
func (c *cache) Set(name string, val string, t time.Duration) {
if t <= 0 {
return
}
c.Store(name, val)
go func(name string, t time.Duration) {
time.Sleep(t)
c.Delete(name)
}(name, t)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xiaoyutab/xgotool.git
git@gitee.com:xiaoyutab/xgotool.git
xiaoyutab
xgotool
xgotool
v0.3.64

搜索帮助