filecache

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMiss        = errors.New("compilation cache: required entry missing")
	ErrStale       = errors.New("compilation cache: stale entry")
	ErrCorrupt     = errors.New("compilation cache: corrupt entry")
	ErrUnsupported = errors.New("compilation cache: engine can't load modules from a persistent cache")
	ErrReadOnly    = errors.New("compilation cache: read-only")
)

These are exposed by the public compilation cache API, see wazy.NewCompilationCacheWithDirReadOnly.

Functions

func ReadOnly added in v0.4.0

func ReadOnly(c Cache) bool

ReadOnly reports whether c only serves hits: a module it doesn't hold must fail rather than be compiled, and it is never written.

Types

type Cache

type Cache interface {
	// Get is called when the runtime is trying to get the cached compiled functions.
	// Implementations are supposed to return compiled function in io.Reader with ok=true
	// if the key exists on the cache. In the case of not-found, this should return
	// ok=false with err=nil. content.Close() is automatically called by
	// the caller of this Get.
	//
	// Note: the returned content won't go through the validation pass of Wasm binary
	// which is applied when the binary is compiled from scratch without cache hit.
	Get(key Key) (content io.ReadCloser, ok bool, err error)
	//
	// Add is called when the runtime is trying to add the new cache entry.
	// The given `content` must be un-modified, and returned as-is in Get method.
	//
	// Note: the `content` is ensured to be safe through the validation phase applied on the Wasm binary.
	Add(key Key, content io.Reader) (err error)
	//
	// Delete is called when the cache on the `key` returned by Get is no longer usable, and
	// must be purged. Specifically, this is called happens when the wazy's version has been changed.
	// For example, that is when there's a difference between the version of compiling wazy and the
	// version of the currently used wazy.
	Delete(key Key) (err error)
}

Cache allows the compiler engine to skip compilation of wasm to machine code where doing so is redundant for the same wasm binary and version of wazy.

This augments the default in-memory cache of compiled functions, by decoupling it from a wazy.Runtime instance. Concretely, a runtime loses its cache once closed. This cache allows the runtime to rebuild its in-memory cache quicker, significantly reducing first-hit penalty on a hit.

See New for the example implementation.

func New

func New(dir string) Cache

New returns a new Cache implemented by fileCache.

func NewReadOnly added in v0.4.0

func NewReadOnly(dir string) Cache

NewReadOnly returns a Cache over dir that only serves hits: Get fails with ErrMiss for an absent entry, and it never writes or deletes anything.

type Key

type Key = [sha256.Size]byte

Key represents the 256-bit unique identifier assigned to each cache entry.

Jump to

Keyboard shortcuts

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