cache

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: Apache-2.0 Imports: 6 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]) KeepValueUpdated added in v1.5.0

func (t *TimeDefinedCache[T]) KeepValueUpdated(stopChannel chan struct{}) error

KeepValueUpdated will keep the value updated in the cache by calling the re-calculation function every minRefreshDuration until the stopChannel is closed.

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
JackTT - Gopher 🇻🇳