1 Star 0 Fork 0

y18618233925 / gutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cache.go 607 Bytes
一键复制 编辑 原始数据 按行查看 历史
phoebus 提交于 2024-04-28 10:53 . init
package utils
import (
"sync"
)
// Cache 是一个内存缓存的简单实现
type Cache struct {
data map[string]interface{}
lock sync.RWMutex
}
// NewCache 创建一个新的缓存实例
func NewCache() *Cache {
return &Cache{
data: make(map[string]interface{}),
}
}
// Set 将一个值与一个键关联
func (c *Cache) Set(key string, value interface{}) {
c.lock.Lock()
defer c.lock.Unlock()
c.data[key] = value
}
// Get 获取与一个键关联的值
func (c *Cache) Get(key string) (interface{}, bool) {
c.lock.RLock()
defer c.lock.RUnlock()
val, ok := c.data[key]
return val, ok
}
Go
1
https://gitee.com/y18618233925/gutils.git
git@gitee.com:y18618233925/gutils.git
y18618233925
gutils
gutils
v0.0.3

搜索帮助

53164aa7 5694891 3bd8fe86 5694891