cache

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: MIT Imports: 3 Imported by: 24

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/bitrise-io/go-steputils/cache"
)

// Create ItemCollectors for listing Bitrise cache include and exclude patterns.
type SampleItemCollector struct{}

// List of include and exclude patterns are collected in a given directory, cacheLevel describes what files should be included in the cache.
func (c SampleItemCollector) Collect(dir string, cacheLevel cache.Level) ([]string, []string, error) {
	return []string{"include_me.md"}, []string{"exclude_me.txt"}, nil
}

func main() {
	// Create a cache, usually using cache.New()
	getterSetter := NewMockGetterSetter()
	testConfig := cache.Config{getterSetter, []cache.VariableSetter{getterSetter}}
	c := testConfig.NewCache()

	for _, collector := range []cache.ItemCollector{SampleItemCollector{}} {
		// Run some Cache ItemCollectors
		in, ex, err := collector.Collect("", cache.LevelDeps)
		if err != nil {
			panic(err)
		}

		// Store the include and exclude patterns in the cache
		c.IncludePath(in...)
		c.ExcludePath(ex...)
	}
	// Commit the cache changes
	if err := c.Commit(); err != nil {
		panic(err)
	}

	printIncludeAndExcludeEnvs(getterSetter)
}

func printIncludeAndExcludeEnvs(getterSetter MockGetterSetter) {
	includePaths, err := getterSetter.Get(cache.CacheIncludePathsEnvKey)
	if err != nil {
		panic(err)
	}
	fmt.Println(includePaths)

	excludePaths, err := getterSetter.Get(cache.CacheExcludePathsEnvKey)
	if err != nil {
		panic(err)
	}
	fmt.Println(excludePaths)
}
Output:

include_me.md

exclude_me.txt

Index

Examples

Constants

View Source
const (
	LevelNone = Level("none")
	LevelDeps = Level("only_deps")
	LevelAll  = Level("all")
)

Cache level

View Source
const CacheExcludePathsEnvKey = "BITRISE_CACHE_EXCLUDE_PATHS"

CacheExcludePathsEnvKey ...

View Source
const CacheIncludePathsEnvKey = "BITRISE_CACHE_INCLUDE_PATHS"

CacheIncludePathsEnvKey ...

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache ...

func New

func New() Cache

New ...

func (*Cache) Commit

func (cache *Cache) Commit() error

Commit ...

func (*Cache) ExcludePath

func (cache *Cache) ExcludePath(item ...string)

ExcludePath ...

func (*Cache) IncludePath

func (cache *Cache) IncludePath(item ...string)

IncludePath ...

type Config

type Config struct {
	VariableGetter  VariableGetter
	VariableSetters []VariableSetter
}

Config ...

func (Config) NewCache

func (c Config) NewCache() Cache

NewCache ...

type EnvmanVariableSetter

type EnvmanVariableSetter struct {
}

EnvmanVariableSetter ...

func (EnvmanVariableSetter) Set

func (e EnvmanVariableSetter) Set(key, value string) error

Set ...

type ItemCollector

type ItemCollector interface {
	Collect(dir string, cacheLevel Level) ([]string, []string, error)
}

ItemCollector ...

type Level

type Level string

Level defines the extent to which caching should be used. - LevelNone: no caching - LevelDeps: only dependencies will be cached - LevelAll: dependencies and build files will be cache

type OSVariableGetter

type OSVariableGetter struct{}

OSVariableGetter ...

func (OSVariableGetter) Get

func (e OSVariableGetter) Get(key string) (string, error)

Get ...

type OSVariableSetter

type OSVariableSetter struct{}

OSVariableSetter ...

func (OSVariableSetter) Set

func (e OSVariableSetter) Set(key, value string) error

Set ...

type VariableGetter

type VariableGetter interface {
	Get(key string) (string, error)
}

VariableGetter ...

func NewOSVariableGetter

func NewOSVariableGetter() VariableGetter

NewOSVariableGetter ...

type VariableSetter

type VariableSetter interface {
	Set(key, value string) error
}

VariableSetter ...

func NewEnvmanVariableSetter

func NewEnvmanVariableSetter() VariableSetter

NewEnvmanVariableSetter ...

func NewOSVariableSetter

func NewOSVariableSetter() VariableSetter

NewOSVariableSetter ...

Jump to

Keyboard shortcuts

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