Help us shape the future of Go! Take the 2026 Go Developer Survey

cache

package
v1.5.0 Latest Latest
Warning

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

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

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
}

Directories

Path Synopsis
codec
contrib/shamaton/msgpack/v3
Package msgpack is a wrapper/cache codec on github.com/shamaton/msgpack/v3.
Package msgpack is a wrapper/cache codec on github.com/shamaton/msgpack/v3.
gob
driver
examples
freecache command
multi command
plugin command
plugins

Jump to

Keyboard shortcuts

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