cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 7 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 {
	*lifecycle.Lifecycle
	// contains filtered or unexported fields
}

Cache implements a cache that loads an entry upon first access (using the provided loader), caches it, and then (if required) periodically refreshes the cache entry according the configured refresh interval. While the entry is being refreshed callers are served the old value of the entry. If a refresh fails then the old value is served and another refresh is attempted at a later time. Refreshing an entry does not cause requests for the entry to be blocked, unless the value of the entry is nil.

func New

func New(loader loader, opts ...Opt) *Cache

New returns a new retriever.

func (*Cache) Get

func (c *Cache) Get(key interface{}) (interface{}, error)

Get returns the cached value for the given key.

func (*Cache) MarkAsStale

func (c *Cache) MarkAsStale(key interface{})

MarkAsStale marks the entry such that it should load immediately (or as soon as possible) without waiting for the next refresh time.

type Opt

type Opt func(opts *options)

Opt specifies a config retriever option.

func WithMaxLoadAttempts

func WithMaxLoadAttempts(value uint) Opt

WithMaxLoadAttempts specifies the maximum number of attempts to unsuccessfully load an entry before it is removed from the cache. (Default is to try forever.)

func WithMonitorInterval

func WithMonitorInterval(value time.Duration) Opt

WithMonitorInterval specifies the interval at which entries are checked if they need to be refreshed.

func WithName

func WithName(value string) Opt

WithName sets the name of the cache. (Used only for logging.)

func WithRefreshInterval

func WithRefreshInterval(value time.Duration) Opt

WithRefreshInterval sets the interval at which each entry in the cache is refreshed. If set to 0 (default) then the items will not be refreshed.

func WithRetryBackoff

func WithRetryBackoff(value time.Duration) Opt

WithRetryBackoff specifies the interval at which an entry in the cache errored out at the last attempt is retried.

Jump to

Keyboard shortcuts

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