cacheval

package
v0.220623.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: CC0-1.0 Imports: 3 Imported by: 0

Documentation

Overview

Atomic value with validity timeout. "modified" timestamp is updated after value, without consistency. 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(new int32)

Updates value and modified timestamp. Both value and timestamp are updated atomically, but not consistently with each other. Costs current timestamp lookup.

Jump to

Keyboard shortcuts

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