Functions
Close
method
#
func (c *ProgCache) Close() error
Close
method
#
func (c *DiskCache) Close() error
Default
function
#
Default returns the default cache to use.
It never returns nil.
func Default() Cache
DefaultDir
function
#
DefaultDir returns the effective GOCACHE setting.
It returns "off" if the cache is disabled,
and reports whether the effective value differs from GOCACHE.
func DefaultDir() (string, bool)
Error
method
#
func (e *entryNotFoundError) Error() string
FileHash
function
#
FileHash returns the hash of the named file.
It caches repeated lookups for a given file,
and the cache entry for a file can be initialized
using SetFileHash.
The hash used by FileHash is not the same as
the hash used by NewHash.
func FileHash(file string) ([HashSize]byte, error)
FuzzDir
method
#
func (c *ProgCache) FuzzDir() string
FuzzDir
method
#
FuzzDir returns a subdirectory within the cache for storing fuzzing data.
The subdirectory may not exist.
This directory is managed by the internal/fuzz package. Files in this
directory aren't removed by the 'go clean -cache' command or by Trim.
They may be removed with 'go clean -fuzzcache'.
TODO(#48526): make Trim remove unused files from this directory.
func (c *DiskCache) FuzzDir() string
Get
method
#
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 (c *DiskCache) Get(id ActionID) (Entry, error)
Get
method
#
func (c *ProgCache) Get(a ActionID) (Entry, error)
GetBytes
function
#
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 GetBytes(c Cache, id ActionID) ([]byte, Entry, error)
GetFile
function
#
GetFile looks up the action ID in the cache and returns
the name of the corresponding data file.
func GetFile(c Cache, id ActionID) (file string, entry Entry, err error)
GetMmap
function
#
GetMmap looks up the action ID in the cache and returns
the corresponding output bytes.
GetMmap should only be used for data that can be expected to fit in memory.
func GetMmap(c Cache, id ActionID) ([]byte, Entry, bool, error)
NewHash
function
#
NewHash returns a new Hash.
The caller is expected to Write data to it and then call Sum.
func NewHash(name string) *Hash
Open
function
#
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 Open(dir string) (*DiskCache, error)
OutputFile
method
#
OutputFile returns the name of the cache file storing output with the given OutputID.
func (c *DiskCache) OutputFile(out OutputID) string
OutputFile
method
#
func (c *ProgCache) OutputFile(o OutputID) string
Put
method
#
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 (c *DiskCache) Put(id ActionID, file io.ReadSeeker) (OutputID, int64, error)
Put
method
#
func (c *ProgCache) Put(a ActionID, file io.ReadSeeker) (_ OutputID, size int64, _ error)
PutBytes
function
#
PutBytes stores the given bytes in the cache as the output for the action ID.
func PutBytes(c Cache, id ActionID, data []byte) error
PutExecutable
method
#
PutExecutable is used to store the output as the output for the action ID into a
file with the given base name, with the executable mode bit set.
It may read file twice. The content of file must not change between the two passes.
func (c *DiskCache) PutExecutable(id ActionID, name string, file io.ReadSeeker) (OutputID, int64, error)
PutNoVerify
function
#
PutNoVerify is like Put but disables the verify check
when GODEBUG=goverifycache=1 is set.
It is meant for data that is OK to cache but that we expect to vary slightly from run to run,
like test output containing times and the like.
func PutNoVerify(c Cache, id ActionID, file io.ReadSeeker) (OutputID, int64, error)
SetFileHash
function
#
SetFileHash sets the hash returned by FileHash for file.
func SetFileHash(file string, sum [HashSize]byte)
Subkey
function
#
Subkey returns an action ID corresponding to mixing a parent
action ID with a string description of the subkey.
func Subkey(parent ActionID, desc string) ActionID
Sum
method
#
Sum returns the hash of the data written previously.
func (h *Hash) Sum() [HashSize]byte
Trim
method
#
Trim removes old cache entries that are likely not to be reused.
func (c *DiskCache) Trim() error
Unwrap
method
#
func (e *entryNotFoundError) Unwrap() error
Write
method
#
Write writes data to the running hash.
func (h *Hash) Write(b []byte) (int, error)
copyFile
method
#
copyFile copies file into the cache, expecting it to have the given
output ID and size, if that file is not present already.
func (c *DiskCache) copyFile(file io.ReadSeeker, executableName string, out OutputID, size int64, perm os.FileMode) error
fileName
method
#
fileName returns the name of the file corresponding to the given id.
func (c *DiskCache) fileName(id [HashSize]byte, key string) string
get
method
#
get is Get but does not respect verify mode, so that Put can use it.
func (c *DiskCache) get(id ActionID) (Entry, error)
init
function
#
func init()
initDefaultCache
function
#
initDefaultCache does the work of finding the default cache
the first time Default is called.
func initDefaultCache() Cache
initEnv
function
#
func initEnv()
markUsed
method
#
markUsed makes a best-effort attempt to update mtime on file,
so that mtime reflects cache access time.
Because the reflection only needs to be approximate,
and to reduce the amount of disk activity caused by using
cache entries, used only updates the mtime if the current
mtime is more than an hour old. This heuristic eliminates
nearly all of the mtime updates that would otherwise happen,
while still keeping the mtimes useful for cache trimming.
markUsed reports whether the file is a directory (an executable cache entry).
func (c *DiskCache) markUsed(file string) (isDir bool)
noteOutputFile
method
#
func (c *ProgCache) noteOutputFile(o OutputID, diskPath string)
put
method
#
func (c *DiskCache) put(id ActionID, executableName string, file io.ReadSeeker, allowVerify bool) (OutputID, int64, error)
putIndexEntry
method
#
putIndexEntry adds an entry to the cache recording that executing the action
with the given id produces an output with the given output id (hash) and size.
func (c *DiskCache) putIndexEntry(id ActionID, out OutputID, size int64, allowVerify bool) error
readLoop
method
#
func (c *ProgCache) readLoop(readLoopDone chan<- struct{...})
reverseHash
function
#
reverseHash returns the input used to compute the hash id.
func reverseHash(id [HashSize]byte) string
send
method
#
func (c *ProgCache) send(ctx context.Context, req *cacheprog.Request) (*cacheprog.Response, error)
startCacheProg
function
#
startCacheProg starts the prog binary (with optional space-separated flags)
and returns a Cache implementation that talks to it.
It blocks a few seconds to wait for the child process to successfully start
and advertise its capabilities.
func startCacheProg(progAndArgs string, fuzzDirCache Cache) Cache
stripExperiment
function
#
stripExperiment strips any GOEXPERIMENT configuration from the Go
version string.
func stripExperiment(version string) string
trimSubdir
method
#
trimSubdir trims a single cache subdirectory.
func (c *DiskCache) trimSubdir(subdir string, cutoff time.Time)
writeToChild
method
#
func (c *ProgCache) writeToChild(req *cacheprog.Request, resc chan<- *cacheprog.Response) (err error)