Skip to content

Commit

Permalink
新增得到所有缓存项
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Jul 12, 2024
1 parent 8042fd7 commit 4fd2550
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions list.go → cacheList.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cacheMemory

import "github.com/farseer-go/collections"

type CacheList[T any] struct {
items map[string]*T
}
Expand All @@ -24,3 +26,12 @@ func (receiver *CacheList[T]) SetIfNotExists(key string, getItem func() *T) {
func (receiver *CacheList[T]) Get(key string) *T {
return receiver.items[key]
}

// ToList 得到所有缓存项
func (receiver *CacheList[T]) ToList() collections.List[T] {
lst := collections.NewList[T]()
for _, t := range receiver.items {
lst.Add(*t)
}
return lst
}

0 comments on commit 4fd2550

Please sign in to comment.