cache

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDependNotValid = errors.New("depend not valid")
View Source
var (
	ErrNil = errors.New("cache: nil")
)

Functions

func IsNil

func IsNil(err error) bool

func Marshal added in v1.1.0

func Marshal(ctx context.Context, data interface{}, options *Options) ([]byte, error)

func Unmarshal added in v1.1.0

func Unmarshal(ctx context.Context, data []byte, v interface{}, options *Options) error

Types

type Cache

type Cache interface {
	GetOrSet(ctx context.Context, key string, set func() (interface{}, error), opts ...Option) Value
	Set(ctx context.Context, key string, val interface{}, opts ...Option) Value
	Get(ctx context.Context, key string, opts ...Option) Value
	Has(ctx context.Context, key string) (bool, error)
	Del(ctx context.Context, key string) error
	Close() error
}

type Depend

type Depend interface {
	Val(ctx context.Context) interface{}
	Valid(ctx context.Context) error
}

type GetOrSetValue added in v1.1.0

type GetOrSetValue struct {
	Value
	Set func() Value
}

func (*GetOrSetValue) Scan added in v1.1.0

func (g *GetOrSetValue) Scan(v interface{}) error

type KeyDepend

type KeyDepend struct {
	Key   string `json:"key"`
	Value int64  `json:"Value"`
	// contains filtered or unexported fields
}

KeyDepend key依赖

func NewKeyDepend

func NewKeyDepend(store Cache, key string) *KeyDepend

func (*KeyDepend) InvalidKey

func (v *KeyDepend) InvalidKey(ctx context.Context) error

InvalidKey 使key失效

func (*KeyDepend) Val

func (v *KeyDepend) Val(ctx context.Context) interface{}

Val 获取依赖的值

func (*KeyDepend) Valid

func (v *KeyDepend) Valid(ctx context.Context) error

Valid 检查依赖是否有效

type NilDep added in v1.1.0

type NilDep struct {
	Depend
}

NilDep 用于set的时候反序列化,减少一次dep判断

func (*NilDep) Valid added in v1.1.0

func (n *NilDep) Valid(ctx context.Context) error

type Option

type Option func(*Options)

func Expiration

func Expiration(t time.Duration) Option

func WithDepend

func WithDepend(depend Depend) Option

func WithKeyDepend

func WithKeyDepend(store Cache, key string) Option

type Options

type Options struct {
	Expiration time.Duration
	Depend     Depend
}

func NewOptions

func NewOptions(opts ...Option) *Options

type Value

type Value interface {
	Result() (string, error)
	Err() error
	Scan(v interface{}) error
	Bytes() ([]byte, error)
	Int64() (int64, error)
	Bool() (bool, error)
}

func NewValue added in v1.1.0

func NewValue(ctx context.Context, data string, options *Options, err ...error) Value

Jump to

Keyboard shortcuts

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