cache

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ReadWrite is the default cache mode
	ReadWrite = "read-write"

	// WriteOnly mode is used to write to the cache but not read from it
	WriteOnly = "write-only"

	// Disabled mode bypasses all cache interactions
	Disabled = "disabled"
)
View Source
const CacheMiss = Error("Item not found in cache")

CacheMiss indicates the cache did not contain a match

Variables

This section is empty.

Functions

func HashCommand added in v0.2.0

func HashCommand(cmd *project.Command) (string, error)

Command returns a SHA1 hash of the command configuration

func MapKeys

func MapKeys(m map[string]string) (result []string)

MapKeys returns a sorted slice containing all keys from the given map

func NewMiddleware

func NewMiddleware(c *Cache) project.RunnerBuilder

NewMiddleware returns caching middleware

Types

type Cache

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

Cache for rule outputs

func New

func New(opts Opts) *Cache

New returns a Cache

func (*Cache) Key

func (c *Cache) Key(ctx context.Context, r *project.Rule) (*Key, error)

Key returns a struct of information that uniquely identifies the Rule's inputs and configuration. This used to store Rule outputs in the cache.

func (*Cache) Read

func (c *Cache) Read(ctx context.Context, r *project.Rule) ([]string, error)

Read rule outputs from the cache

func (*Cache) Write

func (c *Cache) Write(ctx context.Context, r *project.Rule) ([]string, error)

Write rule outputs to the cache

type Entry

type Entry struct {
	Name string `json:"name"`
	Hash string `json:"hash"`
}

Entry carries the name and hash for one item within a Key

type Error

type Error string

Error is used to handle cache misses and the like

func (Error) Error

func (e Error) Error() string

type Key

type Key struct {
	Project     string   `json:"project"`
	Component   string   `json:"component"`
	Rule        string   `json:"rule"`
	Image       string   `json:"image"`
	OutputCount int      `json:"output_count"`
	Inputs      []*Entry `json:"inputs"`
	Deps        []*Entry `json:"deps"`
	Env         []*Entry `json:"env"`
	Toolchain   []*Entry `json:"toolchain"`
	Version     string   `json:"version"`
	Commands    []string `json:"commands"`
	Native      bool     `json:"native,omitempty"`
	// contains filtered or unexported fields
}

Key contains information used to build a key

func (*Key) Compute

func (k *Key) Compute() error

Compute determines the hash for this key

func (*Key) String

func (k *Key) String() string

String returns the key as a hexadecimal string

type Opts added in v0.6.0

type Opts struct {
	Store  store.Store
	Hasher hash.Hasher
	User   string
	Mode   string
}

Opts defines options for initializing a Cache

Jump to

Keyboard shortcuts

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