Skip to content

Commit

Permalink
新增:批量获取Items
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Jul 26, 2024
1 parent 4fd2550 commit cb47452
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions cacheInMemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit cb47452

Please sign in to comment.