filecache

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: BSD-3-Clause Imports: 14 Imported by: 2

README

filecache caches build artifacts in files

It is a copy of the Go internal cmd/go/internal/cache which is used for go build caching.

The default setup from the environment (GOCACHE) has been removed, but the trimming defaults (1 hour mtime resolution, evict files older than 5 days) has been kept. It is also possible to override these with TrimWithLimits.

Documentation

Index

Constants

View Source
const HashSize = sha256.Size

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionID

type ActionID = cache.ActionID

An ActionID is a cache action key, the hash of a complete description of a repeatable computation (command line, environment variables, input file contents, executable contents).

func NewActionID

func NewActionID(p []byte) ActionID

type Cache

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

A Cache is a package cache, backed by a file system directory tree.

func Open

func Open(dir string) (*Cache, error)

Open 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 ActionID) (cache.Entry, error)

Get looks up the action ID in the cache, returning the corresponding output ID and file size, if any. Note that finding an output ID does not guarantee that the saved file for that output ID is still available.

func (*Cache) GetBytes

func (C *Cache) GetBytes(id ActionID) ([]byte, cache.Entry, error)

GetBytes looks up the action ID in the cache and returns the corresponding output bytes. GetBytes should only be used for data that can be expected to fit in memory.

func (*Cache) GetFile

func (C *Cache) GetFile(id ActionID) (file string, entry cache.Entry, err error)

GetFile looks up the action ID in the cache and returns the name of the corresponding data file.

func (*Cache) Put

func (C *Cache) Put(id ActionID, file io.ReadSeeker) (OutputID, 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 (*Cache) SetTrimInterval added in v0.2.0

func (C *Cache) SetTrimInterval(d time.Duration)

SetTrimInterval set the time intervals between Trims (on Put).

func (*Cache) SetTrimLimit added in v0.2.0

func (C *Cache) SetTrimLimit(d time.Duration)

SetTrimLimit set the max age of entries.

func (*Cache) SetTrimSize added in v0.2.0

func (C *Cache) SetTrimSize(n int64)

SetTrimSize set the trim file size (checked on Put).

func (*Cache) Trim

func (C *Cache) Trim() error

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

type Hash added in v0.0.2

type Hash struct {
	hash.Hash
}

func NewHash added in v0.0.2

func NewHash() Hash

func (Hash) SumID added in v0.0.2

func (h Hash) SumID() ID

type ID added in v0.0.2

type ID [HashSize]byte

func SumID added in v0.2.1

func SumID(p []byte) ID

type OutputID

type OutputID = cache.OutputID

An OutputID is a cache output key, the hash of an output of a computation.

Directories

Path Synopsis
cmd
filecache
Package main of filecache implements program memoization: caches the output of the call with the arguments (and possibly the stdin) as key.
Package main of filecache implements program memoization: caches the output of the call with the arguments (and possibly the stdin) as key.

Jump to

Keyboard shortcuts

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