cache

package
Version: v0.0.0-...-0a0b670 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2019 License: MIT Imports: 5 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 {
	GetValue   func() interface{}
	Delay      time.Duration
	NextUpdate time.Time

	sync.RWMutex
	// contains filtered or unexported fields
}

Cache implements a thread-safe cache for polling resources.

func HTTPResponse

func HTTPResponse(rq *http.Request, process func(b []byte) interface{}, client *http.Client, t time.Duration) *Cache

HTTPResponse is a convenience function that makes the http request rq periodically and processes the response with 'process'.

func New

func New(get func() interface{}, delay time.Duration) (c *Cache)

func (*Cache) Get

func (c *Cache) Get() interface{}

Returns a Response with the current value of the Cache as an interface{}.

func (*Cache) Value

func (c *Cache) Value() Response

Returns a Response with the current value of the Cache.

type Response

type Response struct {
	Value interface{}
	Stale bool
	Error error
}

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL