cache

package
v0.0.0-...-0a43815 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Adapted from https://github.com/thought-machine/please Copyright Thought Machine, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Package cache abstracts storing and fetching previously run tasks

Adapted from https://github.com/thought-machine/please Copyright Thought Machine, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Package cache implements our cache abstraction.

Adapted from https://github.com/thought-machine/please Copyright Thought Machine, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Adapted from https://github.com/thought-machine/please Copyright Thought Machine, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	// CacheSourceFS is a constant to indicate local cache hit
	CacheSourceFS = "LOCAL"
	// CacheSourceRemote is a constant to indicate remote cache hit
	CacheSourceRemote = "REMOTE"
	// CacheSourceNone is an empty string because there is no source for a cache miss
	CacheSourceNone = ""
	// CacheEventHit is a constant to indicate a cache hit
	CacheEventHit = "HIT"
	// CacheEventMiss is a constant to indicate a cache miss
	CacheEventMiss = "MISS"
)

Variables

View Source
var ErrNoCachesEnabled = errors.New("no caches are enabled")

ErrNoCachesEnabled is returned when both the filesystem and http cache are unavailable

Functions

func DefaultLocation

func DefaultLocation(repoRoot turbopath.AbsoluteSystemPath) turbopath.AbsoluteSystemPath

DefaultLocation returns the default filesystem cache location, given a repo root

func WriteCacheMetaFile

func WriteCacheMetaFile(path turbopath.AbsoluteSystemPath, config *CacheMetadata) error

WriteCacheMetaFile writes cache metadata file at a path

Types

type ArtifactSignatureAuthentication

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

type Cache

type Cache interface {
	// Fetch returns true if there is a cache it. It is expected to move files
	// into their correct position as a side effect
	Fetch(anchor turbopath.AbsoluteSystemPath, hash string, files []string) (ItemStatus, []turbopath.AnchoredSystemPath, error)
	Exists(hash string) ItemStatus
	// Put caches files for a given hash
	Put(anchor turbopath.AbsoluteSystemPath, hash string, duration int, files []turbopath.AnchoredSystemPath) error
	Clean(anchor turbopath.AbsoluteSystemPath)
	CleanAll()
	Shutdown()
}

Cache is abstracted way to cache/fetch previously run tasks

func New

func New(opts Opts, repoRoot turbopath.AbsoluteSystemPath, client client, recorder analytics.Recorder, onCacheRemoved OnCacheRemoved) (Cache, error)

New creates a new cache

type CacheEvent

type CacheEvent struct {
	Source   string `mapstructure:"source"`
	Event    string `mapstructure:"event"`
	Hash     string `mapstructure:"hash"`
	Duration int    `mapstructure:"duration"`
}

type CacheMetadata

type CacheMetadata struct {
	Hash     string `json:"hash"`
	Duration int    `json:"duration"`
}

CacheMetadata stores duration and hash information for a cache entry so that aggregate Time Saved calculations can be made from artifacts from various caches

func ReadCacheMetaFile

func ReadCacheMetaFile(path turbopath.AbsoluteSystemPath) (*CacheMetadata, error)

ReadCacheMetaFile reads cache metadata file at a path

type ItemStatus

type ItemStatus struct {
	Hit       bool
	Source    string // only relevant if Hit is true
	TimeSaved int    // will be 0 if Hit is false
}

ItemStatus holds whether artifacts exists for a given hash on local and/or remote caching server

func NewCacheMiss

func NewCacheMiss() ItemStatus

NewCacheMiss returns an ItemStatus with the fields set to indicate a cache miss

type OnCacheRemoved

type OnCacheRemoved = func(cache Cache, err error)

OnCacheRemoved defines a callback that the cache system calls if a particular cache needs to be removed. In practice, this happens when Remote Caching has been disabled the but CLI continues to try to use it.

type Opts

type Opts struct {
	OverrideDir    string
	SkipRemote     bool
	SkipFilesystem bool
	Workers        int
	Signature      bool
}

Opts holds configuration options for the cache TODO(gsoltis): further refactor this into fs cache opts and http cache opts

type StreamValidator

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

func (*StreamValidator) CurrentValue

func (sv *StreamValidator) CurrentValue() string

func (*StreamValidator) Validate

func (sv *StreamValidator) Validate(expectedTag string) bool

Jump to

Keyboard shortcuts

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