cache

package
v0.18.3-mocha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheMiss = errors.New("accessor not found in cache")

Functions

This section is empty.

Types

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() (unreg func() error, err error)

EnableMetrics enables metrics for the cache.

func (*AccessorCache) Get

func (bc *AccessorCache) Get(height uint64) (eds.AccessorStreamer, error)

Get retrieves the accessor for a given uint64 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,
	height uint64,
	loader OpenAccessorFn,
) (eds.AccessorStreamer, error)

GetOrLoad attempts to get an item from the cache, and if not found, invokes the provided loader function to load it.

func (*AccessorCache) Has

func (bc *AccessorCache) Has(height uint64) bool

Has checks if accessor for the height is present on the AccessorCache.

func (*AccessorCache) Remove

func (bc *AccessorCache) Remove(height uint64) error

Remove removes the Accessor for a given uint64 from the cache.

type Cache

type Cache interface {
	// Has checks if the Cache contains the eds.AccessorStreamer for the given height.
	Has(height uint64) bool

	// Get returns the eds.AccessorStreamer for the given height.
	Get(height uint64) (eds.AccessorStreamer, 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, height uint64, open OpenAccessorFn) (eds.AccessorStreamer, error)

	// Remove removes an item from Cache.
	Remove(height uint64) error

	// EnableMetrics enables metrics in Cache
	EnableMetrics() (unreg func() error, err 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() (unreg func() error, err error)

func (*DoubleCache) First

func (mc *DoubleCache) First() Cache

func (*DoubleCache) Get

func (mc *DoubleCache) Get(height uint64) (eds.AccessorStreamer, error)

Get looks for an item in all the caches one by one and returns the Cache found item.

func (*DoubleCache) GetOrLoad

func (mc *DoubleCache) GetOrLoad(
	ctx context.Context,
	height uint64,
	loader OpenAccessorFn,
) (eds.AccessorStreamer, error)

GetOrLoad attempts to get an item from the both caches and, if not found, invokes the provided loader function to load it into the first Cache.

func (*DoubleCache) Has

func (mc *DoubleCache) Has(height uint64) bool

Has checks if accessor for the height is present on the AccessorCache.

func (*DoubleCache) Remove

func (mc *DoubleCache) Remove(height uint64) error

Remove removes an item from all underlying caches

func (*DoubleCache) Second

func (mc *DoubleCache) Second() Cache

type NoopCache

type NoopCache struct{}

NoopCache implements noop version of Cache interface

func (NoopCache) EnableMetrics

func (n NoopCache) EnableMetrics() (unreg func() error, err error)

func (NoopCache) Get

func (NoopCache) GetOrLoad

func (n NoopCache) GetOrLoad(ctx context.Context, _ uint64, loader OpenAccessorFn) (eds.AccessorStreamer, error)

func (NoopCache) Has

func (n NoopCache) Has(uint64) bool

func (NoopCache) Remove

func (n NoopCache) Remove(uint64) error

type NoopFile

type NoopFile struct{}

NoopFile implements noop version of eds.AccessorStreamer interface

func (NoopFile) AxisHalf

func (n NoopFile) AxisHalf(context.Context, rsmt2d.Axis, int) (eds.AxisHalf, error)

func (NoopFile) AxisRoots

func (n NoopFile) AxisRoots(context.Context) (*share.AxisRoots, error)

func (NoopFile) Close

func (n NoopFile) Close() error

func (NoopFile) DataHash

func (n NoopFile) DataHash(context.Context) (share.DataHash, error)

func (NoopFile) Reader

func (n NoopFile) Reader() (io.Reader, error)

func (NoopFile) RowNamespaceData

func (NoopFile) Sample

func (n NoopFile) Sample(context.Context, int, int) (shwap.Sample, error)

func (NoopFile) Shares

func (n NoopFile) Shares(context.Context) ([]share.Share, error)

func (NoopFile) Size

func (n NoopFile) Size(context.Context) int

type OpenAccessorFn

type OpenAccessorFn func(context.Context) (eds.AccessorStreamer, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL