(ctx context.Context, desc ocispec.Descriptor)
| 43 | } |
| 44 | |
| 45 | func (provider *providerWithCache) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) { |
| 46 | key := desc.Digest.String() |
| 47 | // If we had en entry already, get the size over |
| 48 | value, ok := provider.cache[key] |
| 49 | if !ok { |
| 50 | newReaderAt, err := provider.native.ReaderAt(ctx, desc) |
| 51 | if err != nil { |
| 52 | return nil, err |
| 53 | } |
| 54 | // Build the final object |
| 55 | value = &readerAtWithCache{ |
| 56 | newReaderAt, |
| 57 | -1, |
| 58 | func() { |
| 59 | delete(provider.cache, key) |
| 60 | }, |
| 61 | } |
| 62 | // Cache it |
| 63 | provider.cache[key] = value |
| 64 | } |
| 65 | |
| 66 | return value, nil |
| 67 | } |
| 68 | |
| 69 | // ReaderAtWithCache implements the content.ReaderAt interface |
| 70 | type readerAtWithCache struct { |
no test coverage detected