cache

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IsNull  = 1
	NotNull = 0
)

null definition

Variables

This section is empty.

Functions

This section is empty.

Types

type DataLoader

type DataLoader interface {
	Key() (key string)
	Value() (value interface{})

	// LoadValue return value need cache
	// if err, nothing will cache
	// if value == nil, and IsNullCached is true, empty will be cached
	LoadValue(c context.Context) (value interface{}, err error)
	Expire() time.Duration
	Desc() string
}

DataLoader cache interface

type MCWrapper

type MCWrapper struct {

	// 是否缓存空值,防止缓存穿透
	IsNullCached bool
	// contains filtered or unexported fields
}

MCWrapper wrapper for mc

func New

func New(mc *memcache.Pool) *MCWrapper

New new memcache wrapper

func (*MCWrapper) Add

func (m *MCWrapper) Add(c context.Context, data DataLoader) (err error)

Add add cache data

func (*MCWrapper) Delete

func (m *MCWrapper) Delete(c context.Context, data DataLoader) (err error)

Delete delete cache data

func (*MCWrapper) Get

func (m *MCWrapper) Get(c context.Context, data DataLoader) (err error)

Get get data

func (*MCWrapper) GetOrLoad

func (m *MCWrapper) GetOrLoad(c context.Context, data DataLoader) (err error)

GetOrLoad get from cache, if not found, then call data.LoadValue to load

Jump to

Keyboard shortcuts

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