cache

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Singleton

type Singleton[V any] struct {
	// contains filtered or unexported fields
}

Singleton is a singleton.

It must be constructed with NewSingleton.

func NewSingleton

func NewSingleton[V any](get func(context.Context) (V, error)) *Singleton[V]

NewSingleton returns a new Singleton.

The get function must only return the zero value of V on error.

func (*Singleton[V]) Get

func (s *Singleton[V]) Get(ctx context.Context) (V, error)

Get gets the value, or returns the error in loading the value.

The given context will be used to load the value if not already loaded.

If Singletons call Singletons, lock ordering must be respected.

Jump to

Keyboard shortcuts

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