Skip to content

Commit

Permalink
新增:本地缓存cacheMemory.List
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Jul 11, 2024
1 parent 0e54f6e commit 1c7dd0b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cacheMemory

type List[T any] struct {
items map[string]*T
}

// SetIfNotExists 写入缓存,如果Key不存在
func (receiver *List[T]) SetIfNotExists(key string, getItem func() *T) {
if _, isExists := receiver.items[key]; !isExists {
receiver.items[key] = getItem()
}
}

// Get 获取数据
func (receiver *List[T]) Get(key string) *T {
return receiver.items[key]
}

0 comments on commit 1c7dd0b

Please sign in to comment.