cache

package module
v0.0.0-...-b0f9e44 Latest Latest
Warning

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

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

README

cache

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create[T comparable](ctx context.Context, name string) (*cacher[T], error)

func CreateInDirectory

func CreateInDirectory[T comparable](ctx context.Context, name string, cacheDir string) (*cacher[T], error)

func CreateListener

func CreateListener[T comparable](source <-chan T) *listeners[T]

func CreateStaticListener

func CreateStaticListener[T comparable](value T) staticListeners[T]

func WaitForCurrent

func WaitForCurrent[T comparable](ctx context.Context, v Version[T]) error

func WaitForValue

func WaitForValue[T comparable](ctx context.Context, v Version[T], value T) error

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[T comparable] interface {
	Cache(ctx context.Context, hasher hash.Hash, wrapped CacheableFunction, versioner Version[T]) ([]byte, error)
	SetDefaultValidity(d time.Duration)
	Close()
}

type Reactive

type Reactive[T comparable] func() T

func (Reactive[_]) CancelNotifyOnChange

func (r Reactive[_]) CancelNotifyOnChange(i int)

func (Reactive[T]) Current

func (r Reactive[T]) Current() T

func (Reactive[_]) HasCurrent

func (r Reactive[_]) HasCurrent() bool

func (Reactive[T]) NotifyOnChange

func (r Reactive[T]) NotifyOnChange(onChanged chan<- T) int

type Version

type Version[T comparable] interface {
	HasCurrent() bool
	Current() T // only valid if HasCurrent()
	NotifyOnChange(onChanged chan<- T) int

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

Version is used to track the current value of something, receiving a push to nominated channel(s) whenever the value changes. The channel will also be pushed the current value, if there is one at the time of registration.

func CreateNullVersion

func CreateNullVersion() Version[string]

CreateNullVersion is used as a no-op, when no version should ever be returned

Jump to

Keyboard shortcuts

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