cache

package
v1.4.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimeDefinedCache

type TimeDefinedCache[T any] struct {
	// contains filtered or unexported fields
}

func NewTimeDefinedCache

func NewTimeDefinedCache[T any](minRefreshDuration time.Duration, useValueLock bool, reCalcFunc func() (T, error)) (*TimeDefinedCache[T], error)

NewTimeDefinedCache creates a new cache that will refresh the value every minRefreshDuration. If the value is requested before the minRefreshDuration has passed, the cached value will be returned. If minRefreshDuration is zero, the value will always be recalculated. In addition, a Set() can be used to explicitly set the value. If useValueLock is set to true, the value will be locked when being set. If the cache won't be used concurrently, it's safe to set this to false.

func (*TimeDefinedCache[T]) Get

func (t *TimeDefinedCache[T]) Get() (T, error)

func (*TimeDefinedCache[T]) Set

func (t *TimeDefinedCache[T]) Set(value T)

Jump to

Keyboard shortcuts

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