Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 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 CachedClock

type CachedClock struct {
	// contains filtered or unexported fields
}

CachedClock provides a fast, low-cost timestamp read for the hot path. It is updated by a background goroutine at a configurable interval (default 10ms for High-performance performance). Hot path reads are atomic loads of an int64 unix-nanoseconds value.

func GetGlobalCachedClock

func GetGlobalCachedClock() *CachedClock

GetGlobalCachedClock returns the singleton cached clock instance.

func NewCachedClock

func NewCachedClock(updateInterval time.Duration) *CachedClock

NewCachedClock creates a CachedClock whose cached timestamp is refreshed by a background goroutine every updateInterval. A non-positive interval defaults to 10ms.

func (*CachedClock) Close

func (cc *CachedClock) Close()

Close stops the background refresh goroutine. It is safe to call multiple times.

func (*CachedClock) GetNsec

func (cc *CachedClock) GetNsec() *atomic.Int64

GetNsec returns a pointer to the atomic cached nanoseconds value.

func (*CachedClock) GetNsecValue

func (cc *CachedClock) GetNsecValue() int64

GetNsecValue returns the cached nanoseconds value directly (for hot path optimization)

func (*CachedClock) Now

func (cc *CachedClock) Now() time.Time

Now returns the cached time as a time.Time.

Jump to

Keyboard shortcuts

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