diff --git a/list.go b/cacheList.go similarity index 69% rename from list.go rename to cacheList.go index 3d45c8a..241c620 100644 --- a/list.go +++ b/cacheList.go @@ -1,5 +1,7 @@ package cacheMemory +import "github.com/farseer-go/collections" + type CacheList[T any] struct { items map[string]*T } @@ -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 +}