Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Accessor ¶
type Accessor interface { Blockstore() (dagstore.ReadBlockstore, error) Reader() io.Reader io.Closer }
Accessor is a interface type returned by cache, that allows to read raw data by reader or create readblockstore
type AccessorCache ¶
type AccessorCache struct {
// contains filtered or unexported fields
}
AccessorCache implements the Cache interface using an LRU cache backend.
func NewAccessorCache ¶
func NewAccessorCache(name string, cacheSize int) (*AccessorCache, error)
func (*AccessorCache) EnableMetrics ¶
func (bc *AccessorCache) EnableMetrics() error
EnableMetrics enables metrics for the cache.
func (*AccessorCache) Get ¶
func (bc *AccessorCache) Get(key shard.Key) (Accessor, error)
Get retrieves the Accessor for a given shard key from the Cache. If the Accessor is not in the Cache, it returns an errCacheMiss.
func (*AccessorCache) GetOrLoad ¶
func (bc *AccessorCache) GetOrLoad( ctx context.Context, key shard.Key, loader func(context.Context, shard.Key) (Accessor, error), ) (Accessor, error)
GetOrLoad attempts to get an item from the cache, and if not found, invokes the provided loader function to load it.
type Cache ¶
type Cache interface { // Get retrieves an item from the Cache. Get(shard.Key) (Accessor, error) // GetOrLoad attempts to get an item from the Cache and, if not found, invokes // the provided loader function to load it into the Cache. GetOrLoad( ctx context.Context, key shard.Key, loader func(context.Context, shard.Key) (Accessor, error), ) (Accessor, error) // Remove removes an item from Cache. Remove(shard.Key) error // EnableMetrics enables metrics in Cache EnableMetrics() error }
Cache is an interface that defines the basic Cache operations.
type DoubleCache ¶
type DoubleCache struct {
// contains filtered or unexported fields
}
DoubleCache represents a Cache that looks into multiple caches one by one.
func NewDoubleCache ¶
func NewDoubleCache(first, second Cache) *DoubleCache
NewDoubleCache creates a new DoubleCache with the provided caches.
func (*DoubleCache) EnableMetrics ¶
func (mc *DoubleCache) EnableMetrics() error
func (*DoubleCache) First ¶
func (mc *DoubleCache) First() Cache
func (*DoubleCache) Get ¶
func (mc *DoubleCache) Get(key shard.Key) (Accessor, error)
Get looks for an item in all the caches one by one and returns the Cache found item.
func (*DoubleCache) Remove ¶
func (mc *DoubleCache) Remove(key shard.Key) error
Remove removes an item from all underlying caches
func (*DoubleCache) Second ¶
func (mc *DoubleCache) Second() Cache
type NoopAccessor ¶
type NoopAccessor struct{}
NoopAccessor implements noop version of Accessor interface
func (NoopAccessor) Blockstore ¶
func (n NoopAccessor) Blockstore() (dagstore.ReadBlockstore, error)
func (NoopAccessor) Close ¶
func (n NoopAccessor) Close() error
func (NoopAccessor) Reader ¶
func (n NoopAccessor) Reader() io.Reader