1 Star 0 Fork 1

爱不爱生活/goboot

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
item.go 615 Bytes
一键复制 编辑 原始数据 按行查看 历史
爱不爱生活 提交于 2022-05-07 14:28 +08:00 . [Fix] 1. item.expires nil pointer bug
package ttlcache
import (
"sync"
"time"
)
// MapItem represents a record in the cache map
type Item struct {
sync.RWMutex
data string
expires *time.Time
}
func (item *Item) touch(duration time.Duration) {
item.Lock()
var expiration time.Time
if item.expires == nil {
expiration = time.Now().Add(duration)
} else {
expiration = item.expires.Add(duration)
}
item.expires = &expiration
item.Unlock()
}
func (item *Item) expired() bool {
var value bool
item.RLock()
if item.expires == nil {
value = true
} else {
value = item.expires.Before(time.Now())
}
item.RUnlock()
return value
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ixxyy/goboot.git
git@gitee.com:ixxyy/goboot.git
ixxyy
goboot
goboot
v0.1.27

搜索帮助