cache

package
v1.0.0-dev.143 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsyncSave

func AsyncSave() func(opt *Option)

func SaveEmpty

func SaveEmpty() func(opt *Option)

func WithoutReplicate

func WithoutReplicate() func(opt *Option)

Types

type Cacheable

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

type Codec

type Codec[T any] interface {
	Encode(T) ([]byte, error)
	Decode([]byte, *T) error
}

type Context

type Context[R any] struct {
	// contains filtered or unexported fields
}

func NewContext

func NewContext[R any](name string, d Driver, m ...Plugin[R]) *Context[R]

func (*Context[R]) Del

func (c *Context[R]) Del(key string) error

func (*Context[R]) Get

func (c *Context[R]) Get(key string) ([]byte, error)

func (*Context[R]) GetContext

func (c *Context[R]) GetContext() context.Context

func (*Context[R]) GetDriver

func (c *Context[R]) GetDriver() Driver

func (*Context[R]) GetName

func (c *Context[R]) GetName() string

func (*Context[R]) Set

func (c *Context[R]) Set(key string, data []byte) error

func (*Context[R]) SetContext

func (c *Context[R]) SetContext(ctx context.Context)

type Driver

type Driver interface {
	Set(ctx context.Context, key string, data []byte) error
	Del(ctx context.Context, key string) error
	Get(ctx context.Context, key string) (data []byte, err error)
}

type Manager

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

func NewManager

func NewManager[T any](name string, c Codec[T], d ...Driver) *Manager[T]

func (*Manager[T]) Del

func (m *Manager[T]) Del(ctx context.Context, key string) error

func (*Manager[T]) Get

func (m *Manager[T]) Get(ctx context.Context, key string) (ok bool, data T, err error)

func (*Manager[T]) GetOrSet

func (m *Manager[T]) GetOrSet(ctx context.Context, key string, cacheable Cacheable[T], opts ...OptionSet) (data T, err error)

func (*Manager[T]) Set

func (m *Manager[T]) Set(ctx context.Context, key string, data T, opts ...OptionSet) (err error)

func (*Manager[T]) Use

func (m *Manager[T]) Use(mid Plugin[T]) *Manager[T]

type Metric

type Metric struct {
	Hit        int
	Miss       int
	GetSuccess int
	GetError   int
	DelSuccess int
	DelError   int
	SetSuccess int
	SetError   int
	Entries    int
	Driver     string
}

type Option

type Option struct {
	SaveEmpty bool
	AsyncSave bool
	Replicate bool
}

type OptionSet

type OptionSet func() func(opt *Option)

type Plugin

type Plugin[R any] interface {
	Del(*Context[R], string) error
	Get(*Context[R], string) ([]byte, error)
	Set(*Context[R], string, []byte) error
}

Jump to

Keyboard shortcuts

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