cache

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Duration  time.Duration // how long to cache data
	LastStats interface{}   // holds the latest update (and the initial one).
	Updater   UpdateFunc    // returns the next update
	// contains filtered or unexported fields
}

A Cache prevents too many API calls to expensive servers. It stores the latest update, and if subsequent calls to Update come before Duration, it returns the cached status update instead.

Set LastStats to an initial value with the type returned by the Updater. Cache panics if the types do not match.

func (*Cache) Update

func (cache *Cache) Update() interface{}

Update is called to get the next update. If the latest update is more recent than Duration, the cached update is returned. Otherwise, the Updater function is called.

type UpdateFunc

type UpdateFunc func() (interface{}, error)

UpdateFunc is the signature of the updater function

Jump to

Keyboard shortcuts

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