cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: Apache-2.0 Imports: 18 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 interface {
	// Set sets a value in the cache for a given key and field
	Set(ctx context.Context, key string, value interface{}) error

	// Get gets the value of a field for a given key
	Get(ctx context.Context, key string, value interface{}) error

	// Delete removes a key from the cache
	Delete(ctx context.Context, key string) error

	// Keys returns a list of keys that match the pattern
	Keys(ctx context.Context, key string) ([]string, error)

	// HealthCheck checks cache health
	HealthCheck(ctx context.Context) error
}

Cache is the interface for a key value cache

func NewMemoizeCache

func NewMemoizeCache(rc redis.UniversalClient, defaultExpiration, cleanupInterval time.Duration, metrics memoizeMetrics) Cache

NewMemoizeCache creates a memoize cache

type DoFn

type DoFn func(item *cache.Item) (interface{}, error)

DoFn returns the item to be cached

type KeyValCache

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

KeyValCache is a cache that stores KeyValue pairs

func NewKeyValCache

func NewKeyValCache(rc redis.UniversalClient, opts ...Options) *KeyValCache

NewKeyValCache instantiates and returns a KeyValCache

func (*KeyValCache) Delete

func (k *KeyValCache) Delete(ctx context.Context, key string) error

Delete can be used to forcefully remove a key from the cache before it's TTL has expired

func (*KeyValCache) Get

func (k *KeyValCache) Get(ctx context.Context, key string, value interface{}) error

Get gets a value from the cache specified by the key

func (*KeyValCache) HealthCheck

func (k *KeyValCache) HealthCheck(ctx context.Context) error

HealthCheck pings the underlying redis cache

func (*KeyValCache) Keys

func (k *KeyValCache) Keys(ctx context.Context, key string) ([]string, error)

Keys returns a list of keys that match the pattern

func (*KeyValCache) Set

func (k *KeyValCache) Set(ctx context.Context, key string, value interface{}) error

Set sets a key in the cache

type MemCache

type MemCache struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

MemCache is an in memory cache that stores a map of keys to a map of fields and their values

func NewMemCache

func NewMemCache() MemCache

NewMemCache creates an initialised MemCache

func (MemCache) Delete

func (m MemCache) Delete(ctx context.Context, key string) error

Delete removes all of the fields and their values for a given key

func (MemCache) Get

func (m MemCache) Get(ctx context.Context, key string, v interface{}) error

Get gets the value of a field for a given key

func (MemCache) HealthCheck

func (m MemCache) HealthCheck(ctx context.Context) error

HealthCheck checks cache health we don't have any connection to check here so just return no errors

func (MemCache) Keys

func (m MemCache) Keys(ctx context.Context, key string) ([]string, error)

Keys returns a list of keys that match the pattern

func (MemCache) Set

func (m MemCache) Set(ctx context.Context, key string, value interface{}) error

Set sets a value in the cache for a given key and field

type MemoizeMetrics

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

MemoizeMetrics implements the memoizeMetrics interface

func NewMemoizeMetrics

func NewMemoizeMetrics(label string, reg *prometheus.Registry) MemoizeMetrics

NewMemoizeMetrics creates a MemoizeMetrics struct that records prometheus metrics that tracks activity in the memoize cache

type MetricsCache

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

MetricsCache is a decorator for a Cache that uses prometheus to track read/write activity in the cache

func NewMetricsCache

func NewMetricsCache(label string, reg prometheus.Registerer, next Cache) MetricsCache

NewMetricsCache creates a MetricsCache

func (MetricsCache) Delete

func (c MetricsCache) Delete(ctx context.Context, key string) (err error)

Delete makes MetricsCache implement the Cache interface. It calls the decorated cache's delete method and uses a prometheus counter and histogram to track the number of calls and how long each call takes

func (MetricsCache) Get

func (c MetricsCache) Get(ctx context.Context, key string, v interface{}) (err error)

Get makes MetricsCache implement the Cache interface. It calls the decorated cache's Get method and uses a prometheus counter and histogram to track the number of calls and how long a Get operation takes.

func (MetricsCache) HealthCheck

func (c MetricsCache) HealthCheck(ctx context.Context) error

HealthCheck calls the decorated cache's HealthCheck method

func (MetricsCache) Keys

func (c MetricsCache) Keys(ctx context.Context, key string) ([]string, error)

Keys makes MetricsCache implement the Cache interface. It calls the decorated cache's Keys method and returns the results. It doesn't record any prometheus metrics.

func (MetricsCache) Set

func (c MetricsCache) Set(ctx context.Context, key string, value interface{}) (err error)

Set makes MetricsCache implement the Cache interface. It calls the decorated cache's Set method and uses a prometheus counter and histogram to track the number of calls and how long a Set operation takes.

type Options

type Options func(k *KeyValCache)

Options defines optional parameters for configuring a KeyValCache

func WithLocalCache

func WithLocalCache(lc cache.LocalCache) Options

WithLocalCache lets you configure the LocalCache e.g. NewKeyValCache("localhost:6379", WithLocalCache(cache.NewTinyLFU(5000, 1 * time.Hour))

func WithMarshalFunc

func WithMarshalFunc(marshalFunc cache.MarshalFunc) Options

WithMarshalFunc lets you set how data is marshaled into the cache

func WithTTL

func WithTTL(ttl time.Duration) Options

WithTTL sets the TTL for keys in the cache

func WithUnmarshalFunc

func WithUnmarshalFunc(unmarshalFunc cache.UnmarshalFunc) Options

WithUnmarshalFunc lets you set how data is unmarshaled from the cache

type Wrapper

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

Wrapper wraps a given cache with logic to store features and segments passed from the golang sdk it translates them from the sdk representation to our rest representation and buckets them per environment this means the proxy can store all the data from all sdk instances in one large cache but to each sdk it appears to have it's own unique cache

func NewWrapper

func NewWrapper(cache Cache, environment string, l log.Logger) *Wrapper

NewWrapper creates a new Wrapper instance

func (*Wrapper) Contains

func (wrapper *Wrapper) Contains(key interface{}) bool

Contains checks if a key is in the cache

func (*Wrapper) Get

func (wrapper *Wrapper) Get(key interface{}) (value interface{}, ok bool)

Get looks up a key's value from the cache.

func (*Wrapper) Keys

func (wrapper *Wrapper) Keys() []interface{}

Keys returns a slice of the keys in the cache

func (*Wrapper) Len

func (wrapper *Wrapper) Len() int

Len returns the number of items in the cache.

func (*Wrapper) Purge

func (wrapper *Wrapper) Purge()

Purge is used to completely clear the cache.

func (*Wrapper) Remove

func (wrapper *Wrapper) Remove(key interface{}) (present bool)

Remove removes the provided key from the cache.

func (*Wrapper) Resize

func (wrapper *Wrapper) Resize(size int) (evicted int)

Resize changes the cache size.

func (*Wrapper) Set

func (wrapper *Wrapper) Set(key interface{}, value interface{}) (evicted bool)

Set sets a new value for a key

func (*Wrapper) SetLogger

func (wrapper *Wrapper) SetLogger(l logger.Logger)

SetLogger sets the wrappers logger from a logger.Logger

func (*Wrapper) Updated

func (wrapper *Wrapper) Updated() time.Time

Updated lastUpdate information

Jump to

Keyboard shortcuts

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