cache

package
v4.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package cache is a generated GoMock package.

Index

Constants

View Source
const (
	// CacheType represents the cache type as a string value
	CacheType = "cache"
)
View Source
const (
	// ChainType represents the chain cache type as a string value
	ChainType = "chain"
)
View Source
const (
	// LoadableType represents the loadable cache type as a string value
	LoadableType = "loadable"
)
View Source
const (
	// MetricType represents the metric cache type as a string value
	MetricType = "metric"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache represents the configuration needed by a cache

func New

func New[T any](store store.StoreInterface) *Cache[T]

New instantiates a new cache entry

func (*Cache[T]) Clear

func (c *Cache[T]) Clear(ctx context.Context) error

Clear resets all cache data

func (*Cache[T]) Delete

func (c *Cache[T]) Delete(ctx context.Context, key any) error

Delete removes the cache item using the given key

func (*Cache[T]) Get

func (c *Cache[T]) Get(ctx context.Context, key any) (T, error)

Get returns the object stored in cache if it exists

func (*Cache[T]) GetCodec

func (c *Cache[T]) GetCodec() codec.CodecInterface

GetCodec returns the current codec

func (*Cache[T]) GetType

func (c *Cache[T]) GetType() string

GetType returns the cache type

func (*Cache[T]) GetWithTTL

func (c *Cache[T]) GetWithTTL(ctx context.Context, key any) (T, time.Duration, error)

GetWithTTL returns the object stored in cache and its corresponding TTL

func (*Cache[T]) Invalidate

func (c *Cache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error

Invalidate invalidates cache item from given options

func (*Cache[T]) Set

func (c *Cache[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error

Set populates the cache item using the given key

type CacheInterface

type CacheInterface[T any] interface {
	Get(ctx context.Context, key any) (T, error)
	Set(ctx context.Context, key any, object T, options ...store.Option) error
	Delete(ctx context.Context, key any) error
	Invalidate(ctx context.Context, options ...store.InvalidateOption) error
	Clear(ctx context.Context) error
	GetType() string
}

CacheInterface represents the interface for all caches (aggregates, metric, memory, redis, ...)

type CacheKeyGenerator

type CacheKeyGenerator interface {
	GetCacheKey() string
}

type ChainCache

type ChainCache[T any] struct {
	// contains filtered or unexported fields
}

ChainCache represents the configuration needed by a cache aggregator

func NewChain

func NewChain[T any](caches ...SetterCacheInterface[T]) *ChainCache[T]

NewChain instantiates a new cache aggregator

func (*ChainCache[T]) Clear

func (c *ChainCache[T]) Clear(ctx context.Context) error

Clear resets all cache data

func (*ChainCache[T]) Delete

func (c *ChainCache[T]) Delete(ctx context.Context, key any) error

Delete removes a value from all available caches

func (*ChainCache[T]) Get

func (c *ChainCache[T]) Get(ctx context.Context, key any) (T, error)

Get returns the object stored in cache if it exists

func (*ChainCache[T]) GetCaches

func (c *ChainCache[T]) GetCaches() []SetterCacheInterface[T]

GetCaches returns all Chained caches

func (*ChainCache[T]) GetType

func (c *ChainCache[T]) GetType() string

GetType returns the cache type

func (*ChainCache[T]) Invalidate

func (c *ChainCache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error

Invalidate invalidates cache item from given options

func (*ChainCache[T]) Set

func (c *ChainCache[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error

Set sets a value in available caches

type LoadFunction

type LoadFunction[T any] func(ctx context.Context, key any) (T, error)

type LoadableCache

type LoadableCache[T any] struct {
	// contains filtered or unexported fields
}

LoadableCache represents a cache that uses a function to load data

func NewLoadable

func NewLoadable[T any](loadFunc LoadFunction[T], cache CacheInterface[T]) *LoadableCache[T]

NewLoadable instantiates a new cache that uses a function to load data

func (*LoadableCache[T]) Clear

func (c *LoadableCache[T]) Clear(ctx context.Context) error

Clear resets all cache data

func (*LoadableCache[T]) Close

func (c *LoadableCache[T]) Close() error

func (*LoadableCache[T]) Delete

func (c *LoadableCache[T]) Delete(ctx context.Context, key any) error

Delete removes a value from cache

func (*LoadableCache[T]) Get

func (c *LoadableCache[T]) Get(ctx context.Context, key any) (T, error)

Get returns the object stored in cache if it exists

func (*LoadableCache[T]) GetType

func (c *LoadableCache[T]) GetType() string

GetType returns the cache type

func (*LoadableCache[T]) Invalidate

func (c *LoadableCache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error

Invalidate invalidates cache item from given options

func (*LoadableCache[T]) Set

func (c *LoadableCache[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error

Set sets a value in available caches

type MetricCache

type MetricCache[T any] struct {
	// contains filtered or unexported fields
}

MetricCache is the struct that specifies metrics available for different caches

func NewMetric

func NewMetric[T any](metrics metrics.MetricsInterface, cache CacheInterface[T]) *MetricCache[T]

NewMetric creates a new cache with metrics and a given cache storage

func (*MetricCache[T]) Clear

func (c *MetricCache[T]) Clear(ctx context.Context) error

Clear resets all cache data

func (*MetricCache[T]) Delete

func (c *MetricCache[T]) Delete(ctx context.Context, key any) error

Delete removes a value from the cache

func (*MetricCache[T]) Get

func (c *MetricCache[T]) Get(ctx context.Context, key any) (T, error)

Get obtains a value from cache and also records metrics

func (*MetricCache[T]) GetType

func (c *MetricCache[T]) GetType() string

GetType returns the cache type

func (*MetricCache[T]) Invalidate

func (c *MetricCache[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error

Invalidate invalidates cache item from given options

func (*MetricCache[T]) Set

func (c *MetricCache[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error

Set sets a value from the cache

type MockCacheInterface

type MockCacheInterface[T any] struct {
	// contains filtered or unexported fields
}

MockCacheInterface is a mock of CacheInterface interface.

func NewMockCacheInterface

func NewMockCacheInterface[T any](ctrl *gomock.Controller) *MockCacheInterface[T]

NewMockCacheInterface creates a new mock instance.

func (*MockCacheInterface[T]) Clear

func (m *MockCacheInterface[T]) Clear(ctx context.Context) error

Clear mocks base method.

func (*MockCacheInterface[T]) Delete

func (m *MockCacheInterface[T]) Delete(ctx context.Context, key any) error

Delete mocks base method.

func (*MockCacheInterface[T]) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockCacheInterface[T]) Get

func (m *MockCacheInterface[T]) Get(ctx context.Context, key any) (T, error)

Get mocks base method.

func (*MockCacheInterface[T]) GetType

func (m *MockCacheInterface[T]) GetType() string

GetType mocks base method.

func (*MockCacheInterface[T]) Invalidate

func (m *MockCacheInterface[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error

Invalidate mocks base method.

func (*MockCacheInterface[T]) Set

func (m *MockCacheInterface[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error

Set mocks base method.

type MockCacheInterfaceMockRecorder

type MockCacheInterfaceMockRecorder[T any] struct {
	// contains filtered or unexported fields
}

MockCacheInterfaceMockRecorder is the mock recorder for MockCacheInterface.

func (*MockCacheInterfaceMockRecorder[T]) Clear

func (mr *MockCacheInterfaceMockRecorder[T]) Clear(ctx interface{}) *gomock.Call

Clear indicates an expected call of Clear.

func (*MockCacheInterfaceMockRecorder[T]) Delete

func (mr *MockCacheInterfaceMockRecorder[T]) Delete(ctx, key interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockCacheInterfaceMockRecorder[T]) Get

func (mr *MockCacheInterfaceMockRecorder[T]) Get(ctx, key interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockCacheInterfaceMockRecorder[T]) GetType

func (mr *MockCacheInterfaceMockRecorder[T]) GetType() *gomock.Call

GetType indicates an expected call of GetType.

func (*MockCacheInterfaceMockRecorder[T]) Invalidate

func (mr *MockCacheInterfaceMockRecorder[T]) Invalidate(ctx interface{}, options ...interface{}) *gomock.Call

Invalidate indicates an expected call of Invalidate.

func (*MockCacheInterfaceMockRecorder[T]) Set

func (mr *MockCacheInterfaceMockRecorder[T]) Set(ctx, key, object interface{}, options ...interface{}) *gomock.Call

Set indicates an expected call of Set.

type MockCacheKeyGenerator

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

MockCacheKeyGenerator is a mock of CacheKeyGenerator interface.

func NewMockCacheKeyGenerator

func NewMockCacheKeyGenerator(ctrl *gomock.Controller) *MockCacheKeyGenerator

NewMockCacheKeyGenerator creates a new mock instance.

func (*MockCacheKeyGenerator) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockCacheKeyGenerator) GetCacheKey

func (m *MockCacheKeyGenerator) GetCacheKey() string

GetCacheKey mocks base method.

type MockCacheKeyGeneratorMockRecorder

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

MockCacheKeyGeneratorMockRecorder is the mock recorder for MockCacheKeyGenerator.

func (*MockCacheKeyGeneratorMockRecorder) GetCacheKey

func (mr *MockCacheKeyGeneratorMockRecorder) GetCacheKey() *gomock.Call

GetCacheKey indicates an expected call of GetCacheKey.

type MockSetterCacheInterface

type MockSetterCacheInterface[T any] struct {
	// contains filtered or unexported fields
}

MockSetterCacheInterface is a mock of SetterCacheInterface interface.

func NewMockSetterCacheInterface

func NewMockSetterCacheInterface[T any](ctrl *gomock.Controller) *MockSetterCacheInterface[T]

NewMockSetterCacheInterface creates a new mock instance.

func (*MockSetterCacheInterface[T]) Clear

func (m *MockSetterCacheInterface[T]) Clear(ctx context.Context) error

Clear mocks base method.

func (*MockSetterCacheInterface[T]) Delete

func (m *MockSetterCacheInterface[T]) Delete(ctx context.Context, key any) error

Delete mocks base method.

func (*MockSetterCacheInterface[T]) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockSetterCacheInterface[T]) Get

func (m *MockSetterCacheInterface[T]) Get(ctx context.Context, key any) (T, error)

Get mocks base method.

func (*MockSetterCacheInterface[T]) GetCodec

GetCodec mocks base method.

func (*MockSetterCacheInterface[T]) GetType

func (m *MockSetterCacheInterface[T]) GetType() string

GetType mocks base method.

func (*MockSetterCacheInterface[T]) GetWithTTL

func (m *MockSetterCacheInterface[T]) GetWithTTL(ctx context.Context, key any) (T, time.Duration, error)

GetWithTTL mocks base method.

func (*MockSetterCacheInterface[T]) Invalidate

func (m *MockSetterCacheInterface[T]) Invalidate(ctx context.Context, options ...store.InvalidateOption) error

Invalidate mocks base method.

func (*MockSetterCacheInterface[T]) Set

func (m *MockSetterCacheInterface[T]) Set(ctx context.Context, key any, object T, options ...store.Option) error

Set mocks base method.

type MockSetterCacheInterfaceMockRecorder

type MockSetterCacheInterfaceMockRecorder[T any] struct {
	// contains filtered or unexported fields
}

MockSetterCacheInterfaceMockRecorder is the mock recorder for MockSetterCacheInterface.

func (*MockSetterCacheInterfaceMockRecorder[T]) Clear

func (mr *MockSetterCacheInterfaceMockRecorder[T]) Clear(ctx interface{}) *gomock.Call

Clear indicates an expected call of Clear.

func (*MockSetterCacheInterfaceMockRecorder[T]) Delete

func (mr *MockSetterCacheInterfaceMockRecorder[T]) Delete(ctx, key interface{}) *gomock.Call

Delete indicates an expected call of Delete.

func (*MockSetterCacheInterfaceMockRecorder[T]) Get

func (mr *MockSetterCacheInterfaceMockRecorder[T]) Get(ctx, key interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockSetterCacheInterfaceMockRecorder[T]) GetCodec

GetCodec indicates an expected call of GetCodec.

func (*MockSetterCacheInterfaceMockRecorder[T]) GetType

GetType indicates an expected call of GetType.

func (*MockSetterCacheInterfaceMockRecorder[T]) GetWithTTL

func (mr *MockSetterCacheInterfaceMockRecorder[T]) GetWithTTL(ctx, key interface{}) *gomock.Call

GetWithTTL indicates an expected call of GetWithTTL.

func (*MockSetterCacheInterfaceMockRecorder[T]) Invalidate

func (mr *MockSetterCacheInterfaceMockRecorder[T]) Invalidate(ctx interface{}, options ...interface{}) *gomock.Call

Invalidate indicates an expected call of Invalidate.

func (*MockSetterCacheInterfaceMockRecorder[T]) Set

func (mr *MockSetterCacheInterfaceMockRecorder[T]) Set(ctx, key, object interface{}, options ...interface{}) *gomock.Call

Set indicates an expected call of Set.

type SetterCacheInterface

type SetterCacheInterface[T any] interface {
	// CacheInterface[T] TODO: Waiting for gomock to support nested interfaces with generics.
	Get(ctx context.Context, key any) (T, error)
	Set(ctx context.Context, key any, object T, options ...store.Option) error
	Delete(ctx context.Context, key any) error
	Invalidate(ctx context.Context, options ...store.InvalidateOption) error
	Clear(ctx context.Context) error
	GetType() string

	GetWithTTL(ctx context.Context, key any) (T, time.Duration, error)

	GetCodec() codec.CodecInterface
}

SetterCacheInterface represents the interface for caches that allows storage (for instance: memory, redis, ...)

Jump to

Keyboard shortcuts

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