cache

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fetch added in v1.9.1

func Fetch(ctx context.Context, ch chan<- FetcherResponse, name string, g func(context.Context) ([]apiclient.APIResponse, error))

Fetch is a convenience function. It calls an API and sends the data back to the cache. If the API fails, the call will be retried maxRetries number of times

Types

type Cache

type Cache struct {
	Fetchers []Fetcher
	// contains filtered or unexported fields
}

Cache holds a list of measurements

func (*Cache) Get

func (c *Cache) Get(name string) (entries []apiclient.APIResponse, found bool)

Get retrieves a cached item

func (*Cache) Run added in v1.9.1

func (c *Cache) Run(ctx context.Context, interval time.Duration)

Run starts the cache and periodically pulls in new data

func (*Cache) Stats

func (c *Cache) Stats() (stats map[string]int)

Stats returns statistics on the cache

type Fetcher

type Fetcher interface {
	Update(ctx context.Context, ch chan<- FetcherResponse)
}

Fetcher interface contains all functions an API interface needs to implement to be used by Cache

type FetcherResponse added in v1.9.1

type FetcherResponse struct {
	Name     string
	Response []apiclient.APIResponse
}

FetcherResponse contains one update from a Fetcher

type Holder

type Holder interface {
	Get(name string) (entries []apiclient.APIResponse, found bool)
	Run(ctx context.Context, interval time.Duration)
	Stats() (stats map[string]int)
}

Holder interface contains all functions required to mock a Cache

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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