From cb47452d82bb584d30af8e8366b92d6522a77758 Mon Sep 17 00:00:00 2001 From: steden <1470804@qq.com> Date: Fri, 26 Jul 2024 18:56:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E8=8E=B7=E5=8F=96Items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cacheInMemory.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cacheInMemory.go b/cacheInMemory.go index 8fb2a51..78700f5 100644 --- a/cacheInMemory.go +++ b/cacheInMemory.go @@ -57,14 +57,31 @@ func (r *cacheInMemory) Get() collections.ListAny { func (r *cacheInMemory) GetItem(cacheId any) any { lst := r.Get() for _, item := range lst.ToArray() { - id := r.GetUniqueId(item) - if cacheId == id { + if cacheId == r.GetUniqueId(item) { return item } } return nil } +func (r *cacheInMemory) GetItems(cacheIds []any) collections.ListAny { + keys := collections.NewList[string]() + for _, cacheId := range cacheIds { + keys.Add(parse.ToString(cacheId)) + } + + lst := r.Get() + items := collections.NewListAny() + + for _, item := range lst.ToArray() { + id := r.GetUniqueId(item) + if keys.Contains(id) { + items.Add(item) + } + } + return items +} + func (r *cacheInMemory) Set(val collections.ListAny) { r.lock.Lock() defer r.lock.Unlock()