gocache

package module
v0.0.0-...-b1c1145 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2019 License: MIT Imports: 4 Imported by: 0

README

gocache

Documentation

Index

Constants

This section is empty.

Variables

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

ErrCacheMiss missed

Functions

This section is empty.

Types

type Cachable

type Cachable interface {
	CacheKey() (string, error)
}

Cachable cachable

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache cache

func New

func New(store Store, defaultCoder Coder) *Cache

New new cache

func (*Cache) Clean

func (c *Cache) Clean(vs ...Cachable) error

Clean clean items

func (*Cache) Delete

func (c *Cache) Delete(keys ...string) error

Delete delete keys...

func (*Cache) Load

func (c *Cache) Load(v Cachable) error

Load load item

func (*Cache) MultiRead

func (c *Cache) MultiRead(newItemFunc func() interface{}, keys ...string) ([]interface{}, error)

MultiRead read multiple items TODO bugfix

Multi Read ALL will always return empty

func (*Cache) MultiWrite

func (c *Cache) MultiWrite(items map[string]interface{}, expires ...int64) error

MultiWrite write multiple items

func (*Cache) Read

func (c *Cache) Read(key string, v interface{}) error

func (*Cache) Save

func (c *Cache) Save(v Cachable, expires ...int64) error

Save save item

func (*Cache) Write

func (c *Cache) Write(key string, v interface{}, expires ...int64) error

Write write key value

type Coder

type Coder interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
}

Coder coder

var Json Coder = &jsonCoder{}
var Jsoniter Coder = jsoniter.ConfigDefault
var Msgpack Coder = &msgpackCoder{}

type Pairs

type Pairs map[string][]byte

Pairs store pairs

func (Pairs) Get

func (pairs Pairs) Get(k string) ([]byte, bool)

Get get

func (Pairs) IsEmpty

func (pairs Pairs) IsEmpty() bool

IsEmpty is empty

func (Pairs) Set

func (pairs Pairs) Set(k string, v []byte)

Set set

func (Pairs) Spread

func (pairs Pairs) Spread() []interface{}

Spread spread

type Store

type Store interface {
	Save(pairs Pairs, expire int64) error
	Get(keys ...string) (Pairs, error)
	Delete(keys ...string) error
	Exists(key string) (bool, error)
}

Store store interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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