1 Star 0 Fork 0

小于的个人工具集/xcache

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
get.go 578 Bytes
一键复制 编辑 原始数据 按行查看 历史
xiaoyutab 提交于 2023-12-19 15:40 +08:00 . 基于内存形实现cache缓存
package xcache
import (
"encoding/json"
"errors"
)
// 获取缓存信息
//
// name 要获取的缓存键
func Get(name string) string {
return _default.Get(name)
}
// 获取缓存信息
//
// name 要获取的缓存键
func GetString(name string) string {
return Get(name)
}
// 读取结构体
//
// key 缓存的key名称
// val 预期读取的类型【使用json串行化进行反解析】
func GetStruct(key string, val any) error {
str := Get(key)
if str == "" {
return errors.New("缓存为空或缓存不存在")
}
return json.Unmarshal([]byte(str), val)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xgotool/xcache.git
git@gitee.com:xgotool/xcache.git
xgotool
xcache
xcache
master

搜索帮助