cache

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

package cache provides constructs to enable caching of commonly required resources from the 3scale 'system' APIs

Index

Constants

View Source
const (
	// DefaultCacheTTL - Default time to wait before marking cached values expired
	DefaultCacheTTL = time.Duration(time.Minute * 5)

	// DefaultCacheRefreshInterval - Default interval at which background process should refresh items
	DefaultCacheRefreshInterval = time.Duration(time.Minute * 3)

	// DefaultCacheLimit - Default max number of items that can be stored in the cache at any time
	// A negative value implies that there is no limit on the number of cached items
	DefaultCacheLimit = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigCache

type ConfigCache struct {
	// contains filtered or unexported fields
}

ConfigCache provides an in-memory solution which implements 'ConfigurationCache'

func NewConfigCache

func NewConfigCache(ttl time.Duration, maxEntries int) *ConfigCache

NewConfigCache returns a ConfigCache configured with the provided inputs It accepts a 'time to live' which will be the default value used to mark cached items as expired Max entries limits the number of objects that can exist in the cache at a given time

func NewDefaultConfigCache

func NewDefaultConfigCache() *ConfigCache

NewDefaultConfigCache returns a ConfigCache configured with the default values

func (*ConfigCache) Delete

func (scp *ConfigCache) Delete(key string)

Delete an element from the cache

func (*ConfigCache) FlushExpired

func (scp *ConfigCache) FlushExpired()

FlushExpired elements from the cache Any element whose expiration date is passed the current time will be removed immediately

func (*ConfigCache) Get

func (scp *ConfigCache) Get(key string) (Value, bool)

Get an element from the cache if it exists The returned bool identifies if the element was present or not

func (*ConfigCache) Refresh

func (scp *ConfigCache) Refresh()

Refresh elements in the cache using the provided callback Elements whose callback returns an error will not be refreshed but wil be left in the cache to expire

func (*ConfigCache) RunRefreshWorker

func (scp *ConfigCache) RunRefreshWorker(interval time.Duration, stop chan struct{}) error

RunRefreshWorker at increments provided by the interval At each interval, elements will be refreshed. See 'Refresh()'

func (*ConfigCache) Set

func (scp *ConfigCache) Set(key string, v Value) error

Set an item in the cache under the provided key Returns an error if the max number of entries in the cache has been reached

type ConfigurationCache

type ConfigurationCache interface {
	// Get retrieves an element from the cache (if present) and returns a result, as well as a boolean value
	// which identifies if the element was present or not
	Get(key string) (Value, bool)
	Set(key string, value Value) error
	Delete(key string)
	FlushExpired()
	Refresh()
}

ConfigurationCache is the interface for managing a cache of `Proxy Config` resource(s)

type RefreshCb

type RefreshCb func() (client.ProxyConfig, error)

RefreshCb defines a callback which can be used to refresh elements in the cache as required

type Value

type Value struct {
	Item client.ProxyConfig
	// contains filtered or unexported fields
}

Value defines the value that must be stored in the cache

func (*Value) SetExpiry

func (v *Value) SetExpiry(t time.Time) *Value

SetExpiry time on a value to override the default expiry time set by the caching implementation

func (*Value) SetRefreshCallback

func (v *Value) SetRefreshCallback(fn RefreshCb) *Value

SetRefreshCallback, the callback that will be used to attempt to refresh an element when requested Retry and backoff logic should be implemented in the callback as required.

Jump to

Keyboard shortcuts

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