diff --git a/cache/map.go b/cache/map.go index 6322cd2..933f1b6 100644 --- a/cache/map.go +++ b/cache/map.go @@ -151,22 +151,18 @@ func (m *MapCache[K, V]) getBatchToMap(e Expend[K, V]) func(c context.Context, k var needIndex = make(map[K]int) var err error mm, err := e.Gets(ctx, key) - if err != nil { - return nil, err + if err != nil || len(key) == len(mm) { + return mm, err } + res = mm var flushKeys []K for i, k := range key { - v, ok := mm[k] + _, ok := mm[k] if !ok { flushKeys = append(flushKeys, k) needIndex[k] = i - } else { - res[k] = v } } - if len(needIndex) < 1 { - return res, nil - } call := func() { m.mux.Lock()