groups

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FillCache

type FillCache struct {
	StatsdClient *statsd.Client
	// contains filtered or unexported fields
}

FillCache is a cache whose entries are calculated and filled on-demand

func NewFillCache

func NewFillCache(fillFunc FillFunc, refreshTTL time.Duration) *FillCache

NewFillCache creates a `FillCache` whose entries will be computed by the given `FillFunc`

func (*FillCache) Get

func (c *FillCache) Get(group string) (MemberSet, bool)

Get returns the cache value for the given key, computing it as necessary

func (*FillCache) RefreshLoop

func (c *FillCache) RefreshLoop(group string) bool

RefreshLoop runs in a separate goroutine for the key in the cache and updates the cache value for that key every refreshTTL

func (*FillCache) Stop

func (c *FillCache) Stop()

Stop halts all goroutines and waits for them to exit before returning

func (*FillCache) Update

func (c *FillCache) Update(group string) (bool, error)

Update recomputes the value for the given key, unless another goroutine is already computing the value, and returns a bool indicating whether the value was updated

type FillFunc

type FillFunc func(string) (MemberSet, error)

FillFunc is a function that computes the value of a cache entry given a string key

type MemberSet

type MemberSet map[string]struct{}

MemberSet represents a set of all the members for a given group key in the cache

type MemberSetCache

type MemberSetCache interface {
	// Get returns a MemberSet from the cache
	Get(string) (MemberSet, bool)
	// Update updates the MemberSet of a given key, return a boolean updated value, and and error
	Update(string) (bool, error)
	// RefreshLoop starts an update refresh loop for a given key and returns a boolean value of it was started
	RefreshLoop(string) bool
	// Stop is a function to stop all goroutines that may have been spun up for the cache.
	Stop()
}

MemberSetCache represents a cache of members of a set

type MockCache

type MockCache struct {
	ListMembershipsFunc func(string) (MemberSet, bool)
	Exists              bool
	Updated             bool
	UpdateError         error
	Refreshed           bool
}

MockCache is a mock of MemberSetCache that can be used for testing purposes

func (*MockCache) Get

func (mc *MockCache) Get(group string) (MemberSet, bool)

Get returns the members and if the set exists

func (*MockCache) RefreshLoop

func (mc *MockCache) RefreshLoop(string) bool

RefreshLoop returns a boolean of if the refresh loop is refreshed

func (*MockCache) Stop

func (mc *MockCache) Stop()

Stop fufills the MemberSetCache interface

func (*MockCache) Update

func (mc *MockCache) Update(string) (bool, error)

Update updates the cache

Jump to

Keyboard shortcuts

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