cache

package module
v0.0.0-...-28a121c Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 15 Imported by: 3

README

cache

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(ctx context.Context, name string) (*cacher, error)

func CreateInDirectory

func CreateInDirectory(ctx context.Context, name string, cacheDir string) (*cacher, error)

func CreateListener

func CreateListener(source chan []byte) *listeners

func WaitForCurrent

func WaitForCurrent(ctx context.Context, v Version) []byte

WaitForCurrent returns the current version, as soon as it is known

Types

type CacheableFunction

type CacheableFunction func(ctx context.Context, stdout io.Writer, stderr io.Writer) (result []byte, err error)

A CacheableFunction is provided with writers for any stdout/stderr they produce, along with a context which may be cancelled.

type Cacher

type Cacher interface {
	Cache(hasher hash.Hash, wrapped CacheableFunction, versioner Version) ([]byte, error)
	SetDefaultValidity(d time.Duration)
	Close()
}

type Reactive

type Reactive func() ([]byte, error)

This type is used when you don't really care about being

notified on changes; it's sufficient to be able to get
the current value on demand.

func Identity

func Identity() Reactive

Use when there is only one version

func Static

func Static(f func() ([]byte, error)) Reactive

Use to provide a version which will not change

func (Reactive) CancelNotifyOnChange

func (r Reactive) CancelNotifyOnChange(i int)

func (Reactive) Current

func (r Reactive) Current() []byte

func (Reactive) NotifyOnChange

func (r Reactive) NotifyOnChange(initial []byte, onChanged context.CancelFunc) int

type Version

type Version interface {
	Current() []byte
	// NotifyOnChange registers a context which should receive a
	// cancelled context if the version changes
	NotifyOnChange(initial []byte, ctxCancel context.CancelFunc) int

	// CancelNotifyOnChange deregisters the NotifyOnChange registration.
	CancelNotifyOnChange(i int)
}

func CreateHybrid

func CreateHybrid(current Reactive, abort Version) Version

func CreateNullVersion

func CreateNullVersion() Version

Jump to

Keyboard shortcuts

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