cache

package
v0.15.9 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSSCache

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

func (*CSSCache) Parse

func (c *CSSCache) Parse(log logger.Log, source logger.Source, options css_parser.Options) css_ast.AST

type CacheSet

type CacheSet struct {
	FSCache          FSCache
	CSSCache         CSSCache
	JSONCache        JSONCache
	JSCache          JSCache
	SourceIndexCache SourceIndexCache
}

This is a cache of the parsed contents of a set of files. The idea is to be able to reuse the results of parsing between builds and make subsequent builds faster by avoiding redundant parsing work. This only works if:

  • The AST information in the cache must be considered immutable. There is no way to enforce this in Go, but please be disciplined about this. The ASTs are shared in between builds. Any information that must be mutated in the AST during a build must be done on a shallow clone of the data if the mutation happens after parsing (i.e. a clone that clones everything that will be mutated and shares only the parts that won't be mutated).

  • The information in the cache must not depend at all on the contents of any file other than the file being cached. Invalidating an entry in the cache does not also invalidate any entries that depend on that file, so caching information that depends on other files can result in incorrect results due to reusing stale data. For example, do not "bake in" some value imported from another file.

  • Cached ASTs must only be reused if the parsing options are identical between builds. For example, it would be bad if the AST parser depended on options inherited from a nearby "package.json" file but those options were not part of the cache key. Then the cached AST could incorrectly be reused even if the contents of that "package.json" file have changed.

func MakeCacheSet

func MakeCacheSet() *CacheSet

type FSCache

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

func (*FSCache) ReadFile

func (c *FSCache) ReadFile(fs fs.FS, path string) (contents string, canonicalError error, originalError error)

type JSCache

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

func (*JSCache) Parse

func (c *JSCache) Parse(log logger.Log, source logger.Source, options js_parser.Options) (js_ast.AST, bool)

type JSONCache

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

func (*JSONCache) Parse

func (c *JSONCache) Parse(log logger.Log, source logger.Source, options js_parser.JSONOptions) (js_ast.Expr, bool)

type SourceIndexCache

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

func (*SourceIndexCache) Get

func (c *SourceIndexCache) Get(path logger.Path, kind SourceIndexKind) uint32

func (*SourceIndexCache) LenHint

func (c *SourceIndexCache) LenHint() uint32

type SourceIndexKind

type SourceIndexKind uint8
const (
	SourceIndexNormal SourceIndexKind = iota
	SourceIndexJSStubForCSS
)

Jump to

Keyboard shortcuts

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