| 727 | } |
| 728 | |
| 729 | func (s resultsCache) get(ctx context.Context, key string) ([]tripperware.Extent, bool) { |
| 730 | found, bufs, _ := s.cache.Fetch(ctx, []string{cache.HashKey(key)}) |
| 731 | if len(found) != 1 { |
| 732 | return nil, false |
| 733 | } |
| 734 | |
| 735 | var resp tripperware.CachedResponse |
| 736 | log, ctx := spanlogger.New(ctx, "unmarshal-extent") //nolint:ineffassign,staticcheck |
| 737 | defer log.Finish() |
| 738 | |
| 739 | log.LogFields(otlog.Int("bytes", len(bufs[0]))) |
| 740 | |
| 741 | if err := proto.Unmarshal(bufs[0], &resp); err != nil { |
| 742 | level.Error(log).Log("msg", "error unmarshalling cached value", "err", err) |
| 743 | log.Error(err) |
| 744 | return nil, false |
| 745 | } |
| 746 | |
| 747 | if resp.Key != key { |
| 748 | return nil, false |
| 749 | } |
| 750 | |
| 751 | // Refreshes the cache if it contains an old proto schema. |
| 752 | for _, e := range resp.Extents { |
| 753 | if e.Response == nil { |
| 754 | return nil, false |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | return resp.Extents, true |
| 759 | } |
| 760 | |
| 761 | func (s resultsCache) put(ctx context.Context, key string, extents []tripperware.Extent) { |
| 762 | buf, err := proto.Marshal(&tripperware.CachedResponse{ |