cache

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package cache solves one of the hardest computer science problems in application to GopherJS compiler outputs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear() error

Clear the cache. This will remove *all* cached artifacts from *all* build configurations.

Types

type BuildCache

type BuildCache struct {
	GOOS      string
	GOARCH    string
	GOROOT    string
	GOPATH    string
	BuildTags []string
	Minify    bool
	// When building for tests, import path of the package being tested. The
	// package under test is built with *_test.go sources included, and since it
	// may be imported by other packages in the binary we can't reuse the "normal"
	// cache.
	TestedPackage string
}

BuildCache manages build artifacts that are cached for incremental builds.

Cache is designed to be non-durable: any store and load errors are swallowed and simply lead to a cache miss. The caller must be able to handle cache misses. Nil pointer to BuildCache is valid and simply disables caching.

BuildCache struct fields represent build parameters which change invalidates the cache. For example, any artifacts that were cached for a minified build must not be reused for a non-minified build. GopherJS version change also invalidates the cache. It is callers responsibility to ensure that artifacts passed the the StoreArchive function were generated with the same build parameters as the cache is configured.

There is no upper limit for the total cache size. It can be cleared programmatically via the Clear() function, or the user can just delete the directory if it grows too big.

TODO(nevkontakte): changes in the input sources or dependencies doesn't currently invalidate the cache. This is handled at the higher level by checking cached archive timestamp against loaded package modification time.

TODO(nevkontakte): this cache could benefit from checksum integrity checks.

func (*BuildCache) LoadArchive

func (bc *BuildCache) LoadArchive(importPath string) *compiler.Archive

LoadArchive returns a previously cached archive of the given package or nil if it wasn't previously stored.

The returned archive would have been built with the same configuration as the build cache was.

func (*BuildCache) StoreArchive

func (bc *BuildCache) StoreArchive(a *compiler.Archive)

StoreArchive compiled archive in the cache. Any error inside this method will cause the cache not to be persisted.

func (BuildCache) String

func (bc BuildCache) String() string

Jump to

Keyboard shortcuts

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