cacheval

package
v0.261016.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: CC0-1.0 Imports: 3 Imported by: 0

Documentation

Overview

Atomic value with validity timeout. Value and "modified" timestamp are stored together in a single atomic word, so readers always observe a consistent (value, timestamp) pair. Usage scenario examples: DNS resolve, sensor reading. All methods except `Init` are thread-safe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Int32

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

func (*Int32) Get

func (c *Int32) Get() int32

Returns current (possibly stale) value. Fast and cheap.

func (*Int32) GetFresh

func (c *Int32) GetFresh() (int32, bool)

Returns current value and true if it's fresh. Costs current timestamp lookup.

func (*Int32) GetOrUpdate

func (c *Int32) GetOrUpdate(f func()) int32

Always returns fresh value. If value is stale, runs `f()`. It is `f()` responsibility to update value with `Set()` method. No cache stampede guard. May return value from concurrent `GetOrUpdate` or `Set`. Costs current timestamp lookup.

func (*Int32) Init

func (c *Int32) Init(valid time.Duration)

Not thread-safe. `valid` duration cannot be changed later.

func (*Int32) Set

func (c *Int32) Set(v int32)

Updates value and modified timestamp. Both value and timestamp are updated atomically as a single consistent unit: readers never observe a timestamp without the corresponding value. Costs current timestamp lookup.

Jump to

Keyboard shortcuts

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