cache

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = errors.New("cache: key not found")
	ErrInActive     = errors.New("cache: inactive")
	ErrNotSupported = errors.New("cache: not supported")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	EnableTraffic bool
	EnableMetrics bool
}

type ConfigOption

type ConfigOption func(*Config)

func WithEnableMetrics

func WithEnableMetrics(enable bool) ConfigOption

func WithEnableTraffic

func WithEnableTraffic(enable bool) ConfigOption

type Interceptor

type Interceptor interface {
	Apply(client *redis.Client)
}

func NewInterceptor

func NewInterceptor(config Config) Interceptor

func NewInterceptorWithOpts

func NewInterceptorWithOpts(opts ...ConfigOption) Interceptor

type Manager

type Manager interface {
	// Get returns the value associated with the given key.
	Get(ctx context.Context, key string) (raw string, err error)
	// Set stores the given value with the given key.
	// if expire is 0, then the key will not expire.
	Set(ctx context.Context, key string, raw string, expire time.Duration) (err error)
	// SetNx stores the given value with the given key if the key does not exist.
	// if expire is 0, then the key will not expire.
	SetNx(ctx context.Context, key string, raw string, expire time.Duration) (existing bool, err error)
	// GetBlob returns the value associated with the given key.
	GetBlob(ctx context.Context, key string, output any) (err error)
	// SetBlob stores the given value with the given key.
	// if expire is 0, then the key will not expire.
	SetBlob(ctx context.Context, key string, val any, expire time.Duration) (err error)
	// Del deletes the given key.
	Del(ctx context.Context, key string) (err error)
	// Expire sets the expiration for the given key.
	// if expire is 0, then the key will not expire.
	Expire(ctx context.Context, key string, expire time.Duration) (err error)
	// Eval evaluates the given script with the given keys and arguments.
	Eval(ctx context.Context, script string, keys []string, args ...any) (val any, err error)
}

func NewLRU added in v1.1.0

func NewLRU(
	capability int,
	onEvict func(key string, val []byte),
	expire time.Duration,
) Manager

func NewLocal

func NewLocal() Manager

func NewRedis added in v1.1.0

func NewRedis(
	client *redis.Client,
) Manager

type MockManager

type MockManager struct {
	mock.Mock
}

MockManager is an autogenerated mock type for the Manager type

func NewMockManager

func NewMockManager(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockManager

NewMockManager creates a new instance of MockManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockManager) Del

func (_m *MockManager) Del(ctx context.Context, key string) error

Del provides a mock function with given fields: ctx, key

func (*MockManager) Eval

func (_m *MockManager) Eval(ctx context.Context, script string, keys []string, args ...interface{}) (interface{}, error)

Eval provides a mock function with given fields: ctx, script, keys, args

func (*MockManager) Expire

func (_m *MockManager) Expire(ctx context.Context, key string, expire time.Duration) error

Expire provides a mock function with given fields: ctx, key, expire

func (*MockManager) Get

func (_m *MockManager) Get(ctx context.Context, key string) (string, error)

Get provides a mock function with given fields: ctx, key

func (*MockManager) GetBlob

func (_m *MockManager) GetBlob(ctx context.Context, key string, output interface{}) error

GetBlob provides a mock function with given fields: ctx, key, output

func (*MockManager) Set

func (_m *MockManager) Set(ctx context.Context, key string, raw string, expire time.Duration) error

Set provides a mock function with given fields: ctx, key, raw, expire

func (*MockManager) SetBlob

func (_m *MockManager) SetBlob(ctx context.Context, key string, val interface{}, expire time.Duration) error

SetBlob provides a mock function with given fields: ctx, key, val, expire

func (*MockManager) SetNx

func (_m *MockManager) SetNx(ctx context.Context, key string, raw string, expire time.Duration) (bool, error)

SetNx provides a mock function with given fields: ctx, key, raw, expire

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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