disk

package
v2.4.4 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const BlockSize = 4096

Actual disk usage will be estimated by rounding file sizes up to the nearest multiple of this number.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, kind cache.EntryKind, hash string, size int64, offset int64) (io.ReadCloser, int64, error)
	GetValidatedActionResult(ctx context.Context, hash string) (*pb.ActionResult, []byte, error)
	GetZstd(ctx context.Context, hash string, size int64, offset int64) (io.ReadCloser, int64, error)
	Put(ctx context.Context, kind cache.EntryKind, hash string, size int64, r io.Reader) error
	Contains(ctx context.Context, kind cache.EntryKind, hash string, size int64) (bool, int64)
	FindMissingCasBlobs(ctx context.Context, blobs []*pb.Digest) ([]*pb.Digest, error)

	MaxSize() int64
	Stats() (totalSize int64, reservedSize int64, numItems int, uncompressedSize int64)
	RegisterMetrics()
}

func New

func New(dir string, maxSizeBytes int64, opts ...Option) (Cache, error)

New returns a new instance of a filesystem-based cache rooted at `dir`, with a maximum size of `maxSizeBytes` bytes and `opts` Options set.

type CacheConfig

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

type EvictCallback

type EvictCallback func(key Key, value lruItem)

EvictCallback is the type of callbacks that are invoked when items are evicted.

type Key

type Key interface{}

Key is the type used for identifying cache items. For non-test code, this is a string of the form "<keyspace>/<hash>". Some test code uses ints for simplicity.

TODO: update the test code to use strings too, then drop all the type assertions.

type Option

type Option func(*CacheConfig) error

func WithAccessLogger

func WithAccessLogger(logger *log.Logger) Option

func WithEndpointMetrics

func WithEndpointMetrics() Option

func WithMaxBlobSize

func WithMaxBlobSize(size int64) Option

func WithProxyBackend

func WithProxyBackend(proxy cache.Proxy) Option

func WithProxyMaxBlobSize

func WithProxyMaxBlobSize(maxProxyBlobSize int64) Option

func WithStorageMode

func WithStorageMode(mode string) Option

func WithZstdImplementation

func WithZstdImplementation(impl string) Option

type SizedLRU

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

SizedLRU is an LRU cache that will keep its total size below maxSize by evicting items. SizedLRU is not thread-safe.

func NewSizedLRU

func NewSizedLRU(maxSize int64, onEvict EvictCallback, initialCapacity int) SizedLRU

NewSizedLRU returns a new SizedLRU cache

func (*SizedLRU) Add

func (c *SizedLRU) Add(key Key, value lruItem) (ok bool)

Add adds a (key, value) to the cache, evicting items as necessary. Add returns false and does not add the item if the item size is larger than the maximum size of the cache, or if the item cannot be added to the cache because too much space is reserved.

Note that this function rounds file sizes up to the nearest BlockSize (4096) bytes, as an estimate of actual disk usage since most linux filesystems default to 4kb blocks.

func (*SizedLRU) Get

func (c *SizedLRU) Get(key Key) (value lruItem, ok bool)

Get looks up a key in the cache

func (*SizedLRU) Len

func (c *SizedLRU) Len() int

Len returns the number of items in the cache

func (*SizedLRU) MaxSize

func (c *SizedLRU) MaxSize() int64

func (*SizedLRU) RegisterMetrics

func (c *SizedLRU) RegisterMetrics()

func (*SizedLRU) Remove

func (c *SizedLRU) Remove(key Key)

Remove removes a (key, value) from the cache

func (*SizedLRU) Reserve

func (c *SizedLRU) Reserve(size int64) (bool, error)

func (*SizedLRU) ReservedSize

func (c *SizedLRU) ReservedSize() int64

func (*SizedLRU) TotalSize

func (c *SizedLRU) TotalSize() int64

func (*SizedLRU) UncompressedSize

func (c *SizedLRU) UncompressedSize() int64

func (*SizedLRU) Unreserve

func (c *SizedLRU) Unreserve(size int64) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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