blobcache

package module
v0.4.0 Latest Latest
Warning

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

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

README

blobcache

A fork of Go's internal build cache but for blobs rather than actions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache is a cache that stores blobs by a hash of their contents.

func NewCache added in v0.3.0

func NewCache(logger *zap.Logger, dir string, newHash func() hash.Hash, hashSize int64, now func() time.Time) (*Cache, error)

NewCache opens and returns the cache in the given directory.

It is safe for multiple processes on a single machine to use the same cache directory in a local file system simultaneously. They will coordinate using operating system file locks and may duplicate effort but will not corrupt the cache.

However, it is NOT safe for multiple processes on different machines to share a cache directory (for example, if the directory were stored in a network file system). File locking is notoriously unreliable in network file systems and may not suffice to protect the cache.

func (*Cache) Get

func (c *Cache) Get(id ID) (file io.ReadSeekCloser, entry Entry, err error)

Get looks up the ID in the cache and returns a reader if found.

func (*Cache) Put

func (c *Cache) Put(file io.ReadSeeker) (ID, int64, error)

Put stores the given file in the cache. It may read file twice. The content of file must not change between the two passes.

func (*Cache) Size

func (c *Cache) Size() (int64, error)

Size returns the total size of the cache in bytes.

func (*Cache) Trim

func (c *Cache) Trim(maxBytes int64) error

Trim removes old cache entries that are likely not to be reused.

type Entry

type Entry struct {
	Size int64
	Time time.Time
}

type ID added in v0.3.0

type ID []byte

type KeyedCache added in v0.3.0

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

KeyedCache is a cache that stores blobs by a key.

func NewKeyedCache added in v0.3.0

func NewKeyedCache(logger *zap.Logger, dir string, newHash func() hash.Hash, hashSize int64, now func() time.Time) (*KeyedCache, error)

func (*KeyedCache) Get added in v0.3.0

func (c *KeyedCache) Get(key string) (file io.ReadSeekCloser, entry KeyedEntry, err error)

Get looks up the ID in the cache and returns a reader if found.

func (*KeyedCache) Put added in v0.3.0

func (c *KeyedCache) Put(key string, file io.ReadSeeker) (ID, int64, error)

Put stores the given output in the cache as the output for the action ID. It may read file twice. The content of file must not change between the two passes.

func (*KeyedCache) Size added in v0.3.0

func (c *KeyedCache) Size() (int64, error)

Size returns the total size of the cache in bytes.

func (*KeyedCache) Trim added in v0.3.0

func (c *KeyedCache) Trim(maxBytes int64) error

Trim removes old cache entries that are likely not to be reused.

type KeyedEntry added in v0.3.0

type KeyedEntry struct {
	OutputID ID
	Size     int64
	Time     time.Time
}

Jump to

Keyboard shortcuts

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