cache

package
v0.0.0-...-5117fa9 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: MIT Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheMiss = errors.New("cache miss")
)

Functions

func Register

func Register(name string, adapter Instance)

Register makes a cache adapter available by the adapter name. If Register is called twice with the same name or if driver is nil, it panics.

Types

type Cache

type Cache interface {
	// get cached value by key.
	Get(key string, dest interface{}) error
	// GetMulti is a batch version of Get.
	GetMulti(keys []string) []interface{}
	// set cached value with key and expire time.
	Set(key string, val interface{}, timeout time.Duration) error
	// delete cached value by key.
	Delete(key string) error
	// increase cached int value by key, as a counter.
	Incr(key string) error
	// decrease cached int value by key, as a counter.
	Decr(key string) error
	// check if cached value exists or not.
	IsExist(key string) bool
	// clear all cache.
	FlushAll() error
	// start gc routine based on config string settings.
	StartAndGC(config map[string]interface{}) error
}

func NewCache

func NewCache(adapterName string, config map[string]interface{}) (adapter Cache, err error)

NewCache Create a new cache driver by adapter name and config string. config need to be correct JSON as string: {"interval":360}. it will start gc automatically.

type Codec

type Codec struct {
}

func (*Codec) Marshal

func (t *Codec) Marshal(v interface{}) ([]byte, error)

func (*Codec) Unmarshal

func (t *Codec) Unmarshal(b []byte, v interface{}) error

type CodecInterface

type CodecInterface interface {
	Marshal(interface{}) (interface{}, error)
	Unmarshal([]byte, interface{}) error
}

the remote cache server need serialize and derialize data

type Instance

type Instance func() Cache

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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