Documentation ¶
Overview ¶
package cache provides constructs to enable caching of commonly required resources from the 3scale 'system' APIs
Index ¶
- Constants
- type ConfigCache
- func (scp *ConfigCache) Delete(key string)
- func (scp *ConfigCache) FlushExpired()
- func (scp *ConfigCache) Get(key string) (Value, bool)
- func (scp *ConfigCache) Refresh()
- func (scp *ConfigCache) RunRefreshWorker(interval time.Duration, stop chan struct{}) error
- func (scp *ConfigCache) Set(key string, v Value) error
- type ConfigurationCache
- type RefreshCb
- type Value
Constants ¶
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()'
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 ¶
SetExpiry time on a value to override the default expiry time set by the caching implementation
func (*Value) SetRefreshCallback ¶
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.