Read implements backend.RawReader
(ctx context.Context, name string, keypath backend.KeyPath, cacheInfo *backend.CacheInfo)
| 80 | |
| 81 | // Read implements backend.RawReader |
| 82 | func (r *readerWriter) Read(ctx context.Context, name string, keypath backend.KeyPath, cacheInfo *backend.CacheInfo) (io.ReadCloser, int64, error) { |
| 83 | var k string |
| 84 | cache := r.cacheFor(cacheInfo) |
| 85 | if cache != nil { |
| 86 | k = key(keypath, name) |
| 87 | b, found := cache.FetchKey(ctx, k) |
| 88 | if found { |
| 89 | return io.NopCloser(bytes.NewReader(b)), int64(len(b)), nil |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // previous implemenation always passed false forward for "shouldCache" so we are matching that behavior by passing nil for cacheInfo |
| 94 | // todo: reevaluate. should we pass the cacheInfo forward? |
| 95 | object, size, err := r.nextReader.Read(ctx, name, keypath, nil) |
| 96 | if err != nil { |
| 97 | return nil, 0, err |
| 98 | } |
| 99 | defer object.Close() |
| 100 | |
| 101 | b, err := tempo_io.ReadAllWithEstimate(object, size) |
| 102 | if err == nil && cache != nil { |
| 103 | store(ctx, cache, cacheInfo.Role, k, b) |
| 104 | } |
| 105 | |
| 106 | return io.NopCloser(bytes.NewReader(b)), size, err |
| 107 | } |
| 108 | |
| 109 | // ReadRange implements backend.RawReader |
| 110 | func (r *readerWriter) ReadRange(ctx context.Context, name string, keypath backend.KeyPath, offset uint64, buffer []byte, cacheInfo *backend.CacheInfo) error { |