| 26 | } |
| 27 | |
| 28 | func (t tiered) Fetch(ctx context.Context, keys []string) ([]string, [][]byte, []string) { |
| 29 | found := make(map[string][]byte, len(keys)) |
| 30 | missing := keys |
| 31 | previousCaches := make([]Cache, 0, len(t)) |
| 32 | |
| 33 | for _, c := range []Cache(t) { |
| 34 | var ( |
| 35 | passKeys []string |
| 36 | passBufs [][]byte |
| 37 | ) |
| 38 | |
| 39 | passKeys, passBufs, missing = c.Fetch(ctx, missing) |
| 40 | tiered(previousCaches).Store(ctx, passKeys, passBufs) |
| 41 | |
| 42 | for i, key := range passKeys { |
| 43 | found[key] = passBufs[i] |
| 44 | } |
| 45 | |
| 46 | if len(missing) == 0 { |
| 47 | break |
| 48 | } |
| 49 | |
| 50 | previousCaches = append(previousCaches, c) |
| 51 | } |
| 52 | |
| 53 | resultKeys := make([]string, 0, len(found)) |
| 54 | resultBufs := make([][]byte, 0, len(found)) |
| 55 | for _, key := range keys { |
| 56 | if buf, ok := found[key]; ok { |
| 57 | resultKeys = append(resultKeys, key) |
| 58 | resultBufs = append(resultBufs, buf) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return resultKeys, resultBufs, missing |
| 63 | } |
| 64 | |
| 65 | func (t tiered) Stop() { |
| 66 | for _, c := range []Cache(t) { |