From 4fd2550a2b3f7b85153864022cd8bef09d0398b1 Mon Sep 17 00:00:00 2001 From: steden <1470804@qq.com> Date: Fri, 12 Jul 2024 23:24:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BE=97=E5=88=B0=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=BC=93=E5=AD=98=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list.go => cacheList.go | 11 +++++++++++ 1 file changed, 11 insertions(+) rename list.go => cacheList.go (69%) 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 +}