cache

package
v1.17.4-rc3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacheEvictionBatchSize = 1000

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is the part of the localstore which keeps track of the chunks that are not part of the reserve but are potentially useful to store for obtaining bandwidth incentives. In order to avoid GC we will only keep track of a fixed no. of chunks as part of the cache and evict a chunk as soon as we go above capacity.

func New

func New(ctx context.Context, store internal.Storage, capacity uint64) (*Cache, error)

New creates a new Cache component with the specified capacity. The store is used here only to read the initial state of the cache before shutdown if there was any.

func (*Cache) Capacity

func (c *Cache) Capacity() uint64

Capacity returns the capacity of the cache.

func (*Cache) Getter

func (c *Cache) Getter(store internal.Storage) storage.Getter

Getter returns a Storage.Getter instance which checks if the chunks accessed are part of cache it will update the cache indexes. If the operation to update the cache indexes fail, we need to fail the operation as this should signal the user of this getter to rollback the operation.

func (*Cache) MoveFromReserve

func (c *Cache) MoveFromReserve(
	ctx context.Context,
	store internal.Storage,
	addrs ...swarm.Address,
) error

MoveFromReserve moves the chunks from the reserve to the cache. This is called when the reserve is full and we need to perform eviction. It avoids the need to delete the chunk and re-add it to the cache.

func (*Cache) Putter

func (c *Cache) Putter(store internal.Storage) storage.Putter

Putter returns a Storage.Putter instance which adds the chunk to the underlying chunkstore and also adds a Cache entry for the chunk.

func (*Cache) Size

func (c *Cache) Size() uint64

Size returns the current size of the cache.

type CacheEntryItem added in v1.17.2

type CacheEntryItem = cacheEntry

exported for migration

Jump to

Keyboard shortcuts

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