Ai
1 Star 0 Fork 0

小于的个人工具集/https

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cache.go 906 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaoyutab 提交于 2023-12-13 14:28 +08:00 . 完成初版的API请求方法
package https
import (
"sync"
"time"
)
// 内建缓存组件
type cache struct{}
// 默认缓存值
var _default_cache map[string]string = map[string]string{}
var _default_cache_sync sync.RWMutex
// 获取缓存的值
//
// name 缓存名称
func (c *cache) Get(name string) string {
_default_cache_sync.RLock()
defer _default_cache_sync.RUnlock()
if v, ok := _default_cache[name]; ok {
return v
}
return ""
}
// 设置缓存项的值
//
// name 设置项名称
// val 缓存项的值
// t 缓存时间 -/0-不缓存
func (c *cache) Set(name string, val string, t time.Duration) {
if t <= 0 {
return
}
_default_cache_sync.Lock()
defer _default_cache_sync.Unlock()
_default_cache[name] = val
go func(name string, t time.Duration) {
timer := time.NewTimer(t)
<-timer.C
_default_cache_sync.Lock()
defer _default_cache_sync.Unlock()
delete(_default_cache, name)
}(name, t)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xgotool/https.git
git@gitee.com:xgotool/https.git
xgotool
https
https
v0.0.1

搜索帮助