cache

package
v1.5.48 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cache provides caching implementations for Go values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateFunc

type CreateFunc[K comparable, V any] func(context.Context, K) (*V, error)

CreateFunc is the function type used to produce new values to cache.

type Live

type Live[K comparable, V any] struct {
	Create CreateFunc[K, V]
	// contains filtered or unexported fields
}

Live is a cache that keeps a cached copy as long as the go runtime determines the value is live.

The Create member can be populated to simplify a call site, ala sync.Pool.New. The zero value is safe to use.

See also: weak.Pointer.

func (*Live[K, V]) Clear

func (c *Live[K, V]) Clear()

Clear removes all cached entries.

No additional calls are made for individual values; the cache simply drops any references it has.

func (*Live[K, V]) Get

func (c *Live[K, V]) Get(ctx context.Context, key K, create CreateFunc[K, V]) (*V, error)

Get returns a pointer to the value associated with the key, calling the "Create" function if populated and the "create" argument is nil.

This function will panic if neither function is provided.

Jump to

Keyboard shortcuts

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