cache

package
v2.0.0-...-1d558e1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnexpectedMessageDomain is the error returned when an SSE message has a message domain we aren't expecting
	ErrUnexpectedMessageDomain = errors.New("unexpected message domain")

	// ErrUnexpectedEventType is the error returned when an SSE message has an event type we aren't expecting
	ErrUnexpectedEventType = errors.New("unexpected event type")
)

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

	// Scan all the keys for given key
	Scan(ctx context.Context, key string) (map[string]string, 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 HashCache

type HashCache struct {
	Cache
	// contains filtered or unexported fields
}

HashCache ...

func NewHashCache

func NewHashCache(c Cache, defaultExpiration, cleanupInterval time.Duration) *HashCache

NewHashCache ...

func (HashCache) Delete

func (hc HashCache) Delete(ctx context.Context, key string) error

Delete key from local cache as well as hash entry in the redis

func (HashCache) Get

func (hc HashCache) Get(ctx context.Context, key string, value interface{}) error

func (HashCache) Set

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

Set adds hash key entry for the given key

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) Scan

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

Scan returns a map 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(_ 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(_ 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(_ 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(_ context.Context, key string) ([]string, error)

Keys returns a list of keys that match the pattern

func (MemCache) Scan

func (m MemCache) Scan(_ context.Context, _ string) (map[string]string, error)

Scan all the keys for given key

func (MemCache) Set

func (m MemCache) Set(_ 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) Scan

func (c MetricsCache) Scan(ctx context.Context, key string) (m map[string]string, err error)

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 Refresher

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

Refresher is a type for handling SSE events from Harness Saas

func NewRefresher

func NewRefresher(l log.Logger, config config, client domain.ClientService, inventory domain.InventoryRepo, authRepo domain.AuthRepo, flagRepo domain.FlagRepo, segmentRepo domain.SegmentRepo) Refresher

NewRefresher creates a Refresher

func (Refresher) HandleMessage

func (s Refresher) HandleMessage(ctx context.Context, msg domain.SSEMessage) error

HandleMessage makes Refresher implement the MessageHandler interface

Jump to

Keyboard shortcuts

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