cache

package
v0.0.0-...-93f578c Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotFound = fmt.Errorf("not found")
)

Functions

func IsNotFound

func IsNotFound(err error) bool

func Load

func Load[T any, D Decoder](ctx context.Context, c ByteCache, d D, key string) (*T, error)

func LoadEx

func LoadEx[T any, D Decoder, E Encoder](ctx context.Context, c ByteCache, d D, e E, sf *singleflight.Group, key string, expiration time.Duration, builder func() (obj *T, err error)) (*T, error)

func LoadJson

func LoadJson[T any](ctx context.Context, c ByteCache, key string) (*T, error)

func LoadJsonEx

func LoadJsonEx[T any](ctx context.Context, c ByteCache, sf *singleflight.Group, key string, expiration time.Duration, builder func() (obj *T, err error)) (*T, error)

func Save

func Save[T any, E Encoder](ctx context.Context, c ByteCache, e E, key string, value *T, expiration time.Duration) error

func SaveJson

func SaveJson[T any](ctx context.Context, c ByteCache, key string, value *T, expiration time.Duration) error

Types

type ByteCache

type ByteCache Cache[[]byte]

type Cache

type Cache[S any] interface {
	Set(ctx context.Context, key string, val S, expiration time.Duration) error
	Get(ctx context.Context, key string) (*S, error)
	Del(ctx context.Context, key string) error
	MultiSet(ctx context.Context, valMap map[string]S, expiration time.Duration) error
	MultiGet(ctx context.Context, keys []string) (map[string]S, error)
	MultiDel(ctx context.Context, keys []string) error
	DelAll(ctx context.Context) error
	io.Closer
}

type Decoder

type Decoder interface {
	Unmarshal(data []byte, val any) error
}

type DecoderFunc

type DecoderFunc func(data []byte, val any) error

func (DecoderFunc) Unmarshal

func (d DecoderFunc) Unmarshal(data []byte, val any) error

type Encoder

type Encoder interface {
	Marshal(val any) ([]byte, error)
}

type EncoderFunc

type EncoderFunc func(val any) ([]byte, error)

func (EncoderFunc) Marshal

func (e EncoderFunc) Marshal(val any) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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