cache

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

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

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

README

cache

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

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

func CreateInDirectory

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

func CreateListener

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

func CreateReactiveListener

func CreateReactiveListener[T comparable](r Reactive[T], validity time.Duration) *reactiveListeners[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[valueT any] func(ctx context.Context, stdout io.Writer, stderr io.Writer) (result valueT, 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[valueT any, versionT comparable] interface {
	Call(ctx context.Context, wrapped SilentCacheableFunction[valueT], version versionT) (valueT, error)
	Cache(ctx context.Context, hasher hash.Hash, wrapped CacheableFunction[valueT], versioner Version[versionT]) (valueT, error)
	SetDefaultValidity(d time.Duration)
	Close()
}

type Reactive

type Reactive[T comparable] func() (T, error)

type SilentCacheableFunction

type SilentCacheableFunction[valueT any] func(ctx context.Context) (result valueT, err error)

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