gocachemanager

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheMiss = errors.New("cache miss")
View Source
var ErrInvalidSingleFlightType = errors.New(
	"invalid single flight type returned from refreshing the cache",
)

Functions

This section is empty.

Types

type CacheManager

type CacheManager[TInput proto.Message, TOutput proto.Message] struct {
	// contains filtered or unexported fields
}

func NewCacheManager

func NewCacheManager[TInput proto.Message, TOutput proto.Message](
	prefix string,
	factory func() TOutput,
	updateFn func(context.Context, TInput, map[string]any) (TOutput, error),
	options ...CacheOption,
) (*CacheManager[TInput, TOutput], error)

func (*CacheManager[TInput, TOutput]) Delete added in v0.6.0

func (cm *CacheManager[TInput, TOutput]) Delete(
	ctx context.Context,
	input TInput,
	dependencies ...map[string]any,
) error

func (*CacheManager[TInput, TOutput]) Get

func (cm *CacheManager[TInput, TOutput]) Get(
	ctx context.Context,
	input TInput,
	dependencies ...map[string]any,
) (TOutput, error)

func (*CacheManager[TInput, TOutput]) Refresh

func (cm *CacheManager[TInput, TOutput]) Refresh(
	ctx context.Context,
	input TInput,
	dependencies ...map[string]any,
) (TOutput, error)

func (*CacheManager[TInput, TOutput]) Replace added in v0.6.0

func (cm *CacheManager[TInput, TOutput]) Replace(
	ctx context.Context,
	input TInput,
	newValue TOutput,
	dependencies ...map[string]any,
) (TOutput, error)

type CacheOption

type CacheOption func(*CacheSettings)

CacheOption is an interface for applying cache settings.

func WithExpiration added in v0.4.0

func WithExpiration(expiration time.Duration) CacheOption

func WithGzip added in v0.6.3

func WithGzip() CacheOption

WithGzip is a cache option for enable byte compression.

func WithInMemoryCacheSize

func WithInMemoryCacheSize(inMemoryCacheSize int64) CacheOption

func WithPrometheusNamespace added in v0.6.2

func WithPrometheusNamespace(prometheusNamespace string) CacheOption

WithPrometheusNamespace is a cache option for setting the Prometheus namespace.

func WithPrometheusPrefix

func WithPrometheusPrefix(prometheusPrefix string) CacheOption

WithPrometheusPrefix is a cache option for setting the Prometheus prefix.

func WithRedisConnection

func WithRedisConnection(redisConnection string) CacheOption

WithRedisConnection is a cache option for setting the Redis connection string.

func WithRedisPassword added in v0.8.0

func WithRedisPassword(redisPassword string) CacheOption

WithRedisPassword is a cache option for setting the Redis password.

func WithRedisTLS added in v0.8.0

func WithRedisTLS(redisTLS bool) CacheOption

WithRedisTLS is a cache option for setting the Redis TLS.

func WithSkipInMemoryCache

func WithSkipInMemoryCache() CacheOption

WithSkipInMemoryCache is a cache option for skipping the in-memory cache.

type CacheSettings

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

CacheSettings contains the configuration for building a cache manager.

func DefaultCacheSettings

func DefaultCacheSettings() *CacheSettings

DefaultCacheSettings returns the default cache settings.

type GoCacheWrapper

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

func NewGoCacheWrapper

func NewGoCacheWrapper(
	prefix string,
	expiration time.Duration,
	settings *CacheSettings,
) (*GoCacheWrapper, error)

func (*GoCacheWrapper) Delete added in v0.6.0

func (gcw *GoCacheWrapper) Delete(ctx context.Context, key []byte) error

func (*GoCacheWrapper) Get

func (gcw *GoCacheWrapper) Get(ctx context.Context, key []byte) ([]byte, error)

func (*GoCacheWrapper) Set

func (gcw *GoCacheWrapper) Set(ctx context.Context, key []byte, value []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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