1 Star 1 Fork 1

xiaoyutab/xgotool

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
cache.go 592 Bytes
Copy Edit Raw Blame History
xiaoyutab authored 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.60

Search