github.com/celestiaorg/celestia-node@v0.15.0-beta.1/share/eds/cache/cache.go (about) 1 package cache 2 3 import ( 4 "context" 5 "errors" 6 "io" 7 8 "github.com/filecoin-project/dagstore" 9 "github.com/filecoin-project/dagstore/shard" 10 logging "github.com/ipfs/go-log/v2" 11 "go.opentelemetry.io/otel" 12 ) 13 14 var ( 15 log = logging.Logger("share/eds/cache") 16 meter = otel.Meter("eds_store_cache") 17 ) 18 19 var ( 20 errCacheMiss = errors.New("accessor not found in blockstore cache") 21 ) 22 23 // Cache is an interface that defines the basic Cache operations. 24 type Cache interface { 25 // Get retrieves an item from the Cache. 26 Get(shard.Key) (Accessor, error) 27 28 // GetOrLoad attempts to get an item from the Cache and, if not found, invokes 29 // the provided loader function to load it into the Cache. 30 GetOrLoad( 31 ctx context.Context, 32 key shard.Key, 33 loader func(context.Context, shard.Key) (Accessor, error), 34 ) (Accessor, error) 35 36 // Remove removes an item from Cache. 37 Remove(shard.Key) error 38 39 // EnableMetrics enables metrics in Cache 40 EnableMetrics() error 41 } 42 43 // Accessor is a interface type returned by cache, that allows to read raw data by reader or create 44 // readblockstore 45 type Accessor interface { 46 Blockstore() (dagstore.ReadBlockstore, error) 47 Reader() io.Reader 48 io.Closer 49 }