cache

package
v0.13.4 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

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() (CloseMetricsFn, 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.

func (*AccessorCache) Remove

func (bc *AccessorCache) Remove(key shard.Key) error

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

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() (CloseMetricsFn, error)
}

Cache is an interface that defines the basic Cache operations.

type CloseMetricsFn added in v0.13.4

type CloseMetricsFn func() error

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() (CloseMetricsFn, 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

type NoopCache

type NoopCache struct{}

NoopCache implements noop version of Cache interface

func (NoopCache) EnableMetrics

func (n NoopCache) EnableMetrics() (CloseMetricsFn, error)

func (NoopCache) Get

func (n NoopCache) Get(shard.Key) (Accessor, error)

func (NoopCache) GetOrLoad

func (NoopCache) Remove

func (n NoopCache) Remove(shard.Key) error

Jump to

Keyboard shortcuts

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