Documentation ¶
Index ¶
- Variables
- func Error(a ...interface{}) error
- func Errorf(format string, a ...interface{}) error
- func NewPseudoRand() *rand.Rand
- func RandIntInRange(r *rand.Rand, min, max int) int
- func RetryWithBackoff(fn func() bool) error
- func RetryWithBackoffOptions(opts Options, fn func() bool) error
- type Key
- type LRUCache
- type Options
Constants ¶
This section is empty.
Variables ¶
var CachedRand = NewPseudoRand()
CachedRand is a global singleton rand.Rand object cached for one-off purposes to generate random numbers.
Functions ¶
func Error ¶
func Error(a ...interface{}) error
Error is a passthrough to fmt.Error, with an additional prefix containing the filename and line number.
func Errorf ¶
Errorf is a passthrough to fmt.Errorf, with an additional prefix containing the filename and line number.
func NewPseudoRand ¶
NewPseudoRand returns an instance of math/rand.Rand seeded from crypto/rand so we can easily and cheaply generate unique streams of numbers.
func RandIntInRange ¶
RandIntInRange returns a value in [min, max)
func RetryWithBackoff ¶
RetryWithBackoff is uses default retry constants to implement an exponential backoff. When fn returns true, retry ends. Returns an error if the maximum number of retries is exceeded.
func RetryWithBackoffOptions ¶
RetryWithBackoffOptions implements retry with exponential backoff using the supplied options as parameters.
Types ¶
type Key ¶
type Key interface{}
A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators
type LRUCache ¶
type LRUCache struct { // MaxEntries is the maximum number of cache entries before // an item is evicted. Zero means no limit. MaxEntries int // OnEvicted optionally specificies a callback function to be // executed when an entry is purged from the cache. OnEvicted func(key Key, value interface{}) // contains filtered or unexported fields }
LRUCache is an LRU cache. It is not safe for concurrent access.
func NewLRUCache ¶
NewLRUCache creates a new LRUCache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.
func (*LRUCache) RemoveOldest ¶
func (c *LRUCache) RemoveOldest()
RemoveOldest removes the oldest item from the cache.
type Options ¶
type Options struct { Backoff time.Duration // Default retry backoff interval MaxBackoff time.Duration // Maximum retry backoff interval Constant float64 // Default backoff constant MaxAttempts int // Maximum number of attempts (0 for infinite) }
Options provides control of retry loop logic via the RetryWithBackoffOptions method.