cache

package
v0.17.0-llm.8 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheRecursiveCall = fmt.Errorf("recursive call detected")

Functions

This section is empty.

Types

type Cache added in v0.16.3

type Cache[K comparable, V any] interface {
	// Using the given key, either return an already cached value for that key or initialize
	// an entry in the cache with the given value for that key.
	GetOrInitializeValue(context.Context, K, V) (Result[K, V], error)

	// Using the given key, either return an already cached value for that key or initialize a
	// new value using the given function. If the function returns an error, the error is returned.
	GetOrInitialize(
		context.Context,
		K,
		func(context.Context) (V, error),
	) (Result[K, V], error)

	// Using the given key, either return an already cached value for that key or initialize a
	// new value using the given function. If the function returns an error, the error is returned.
	// The function can also return an optional post call function that will be set on the returned
	// result so callers of this function can call it when post-processing of all results (cached or
	// not) is needed.
	GetOrInitializeWithPostCall(
		context.Context,
		K,
		func(context.Context) (V, PostCallFunc, error),
	) (Result[K, V], error)
}

func NewCache added in v0.16.3

func NewCache[K comparable, V any]() Cache[K, V]

type PostCallFunc added in v0.16.3

type PostCallFunc = func(context.Context) error

type Result

type Result[K comparable, V any] interface {
	Result() V
	Release()
	PostCall(context.Context) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳