Documentation
¶
Index ¶
- func WithCacheUpdateHandler[T any](updateHandler CacheUpdateHandler[T]) option
- func WithErrorHandler(errorHandler ErrorHandler) option
- func WithLogger(log *zap.Logger) option
- func WithMetricsSink(sink metrics.MetricSink) option
- func WithRetryAfterExpirarionDelay(delay time.Duration) option
- func WithRetryOptions(retryOpts []retry.Option) option
- type CacheUpdateHandler
- type ErrorHandler
- type ExpiringValue
- type Fetcher
- type Maintainer
- type RefreshAtFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithCacheUpdateHandler ¶
func WithCacheUpdateHandler[T any](updateHandler CacheUpdateHandler[T]) option
func WithErrorHandler ¶
func WithErrorHandler(errorHandler ErrorHandler) option
func WithLogger ¶
func WithMetricsSink ¶
func WithMetricsSink(sink metrics.MetricSink) option
func WithRetryAfterExpirarionDelay ¶
If a value is not renewed prior to its expiration, the maintainer uses a linear retry with a default delay of 10s. WithRetryAfterExpirarionDelay sets this delay to another value if desired by the user. Decreasing the delay does speedup recovery once the provider is available, but also increases the impact of the provider on recovery.
func WithRetryOptions ¶
Types ¶
type CacheUpdateHandler ¶
type CacheUpdateHandler[T any] func(T)
CacheUpdateHandler is called every time the cached value is updated if requested as an option The value provided is the ExpiringValue construct which is itself containing the value within the cache The handler must not modify the value provided
type ErrorHandler ¶
type ErrorHandler func(error)
ErrorHandler is called every time an error is returned when attempting to update the cached value
type ExpiringValue ¶
type Maintainer ¶
type Maintainer[T any] struct { // contains filtered or unexported fields }
Maintainer is a Refresh-Ahead Cache used to ensure that a ExpiringValue is kept valid for a given RefreshAtFunc. Any call to execute must be done under the syncLock to ensure there is no concurrent calls to the provider
func NewMaintainer ¶
func NewMaintainer[T any](fetcher Fetcher[T], refreshAtFunc RefreshAtFunc, options ...option) *Maintainer[T]
func (*Maintainer[T]) Close ¶
func (m *Maintainer[T]) Close()
func (*Maintainer[T]) Get ¶
func (m *Maintainer[T]) Get(ctx context.Context) (T, error)
Get returns the ExpiringValue returned by Fetcher until the ExpiringValue expires.
func (*Maintainer[T]) IsClosed ¶
func (m *Maintainer[T]) IsClosed() bool
type RefreshAtFunc ¶
RefreshAtFunc returns the time.Time to re-fetch the ExpiringValue. This returned time.Time should never be in the past.
func NewPercentageRemainingRefreshAt ¶
func NewPercentageRemainingRefreshAt(renewAfterPercentage float64, jitterPercentage float64) RefreshAtFunc
NewPercentageRemainingRefreshAt is a basic RefreshAtFunc for calculating the time.Time at which to fetch a ExpiringValue based on the remaining percentage of the lifetime of a ExpiringValue.
renewAfterPercentage is the percentage of time remaining at which point a ExpiringValue should be re-fetched. jitterPercentage is the maximum percentage of (notAfter.Sub(notBefore) * renewAfterPercentage) to use for calculating a jitter value.
i.e. if notBefore and notAfter are 60s apart, renewAfterPercentage is 0.33, and jitter percentage is 10%, the non jittered time will be 60s * 0.33, or 20s from now, with an added jitter of 0-2 (20s * 10%) seconds, for a final return value evenly spaced between 20 and 22 seconds from now.