(ctx context.Context, keys []string, opts ...Option)
| 151 | } |
| 152 | |
| 153 | func (l *LRUCache) GetMultiWithError(ctx context.Context, keys []string, opts ...Option) (result map[string][]byte, err error) { |
| 154 | l.requests.Add(float64(len(keys))) |
| 155 | l.mtx.Lock() |
| 156 | defer l.mtx.Unlock() |
| 157 | var ( |
| 158 | found = make(map[string][]byte, len(keys)) |
| 159 | miss = make([]string, 0, len(keys)) |
| 160 | now = time.Now() |
| 161 | ) |
| 162 | |
| 163 | for _, k := range keys { |
| 164 | item, ok := l.lru.Get(k) |
| 165 | if !ok { |
| 166 | miss = append(miss, k) |
| 167 | continue |
| 168 | } |
| 169 | if item.ExpiresAt.After(now) { |
| 170 | found[k] = item.Data |
| 171 | continue |
| 172 | } |
| 173 | l.lru.Remove(k) |
| 174 | miss = append(miss, k) |
| 175 | |
| 176 | } |
| 177 | l.hits.Add(float64(len(found))) |
| 178 | |
| 179 | if len(miss) > 0 { |
| 180 | result, err = l.c.GetMultiWithError(ctx, miss, opts...) |
| 181 | for k, v := range result { |
| 182 | // we don't know the ttl of the result, so we use the default one. |
| 183 | l.lru.Add(k, &Item{ |
| 184 | Data: v, |
| 185 | ExpiresAt: now.Add(l.defaultTTL), |
| 186 | }) |
| 187 | found[k] = v |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | return found, err |
| 192 | } |
| 193 | |
| 194 | func (l *LRUCache) Name() string { |
| 195 | return "in-memory-" + l.name |
no test coverage detected