Skip to content

Commit

Permalink
增加缓存项是否为Nil
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Jul 12, 2024
1 parent 3a64d4f commit 8042fd7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ func NewCache[T any]() CacheList[T] {
// SetIfNotExists 写入缓存,如果Key不存在
func (receiver *CacheList[T]) SetIfNotExists(key string, getItem func() *T) {
if _, isExists := receiver.items[key]; !isExists {
receiver.items[key] = getItem()
item := getItem()
if item != nil {
receiver.items[key] = item
}
}
}

Expand Down

0 comments on commit 8042fd7

Please sign in to comment.