koko

package module
v0.0.0-...-12687a0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2019 License: MIT Imports: 6 Imported by: 0

README

Koko

Koko is a cache manager. It implements strategies used in cache, e.g. read through.

Example

example.go

Introduction

Koko works with Cache drivers and Callbacks.

  • Cache drivers wraps caches for operations like read and write. It's easy to implement a driver. Koko now provides simple driver for redis and sync.Map.
  • Callbacks is called in situations like cache missing. With cache missing, you need to provide data for cache.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacheMissed cacheMissed

Functions

func BatchReadThrough

func BatchReadThrough(c BatchCache, miss BatchRead, keys interface{}) (interface{}, error)

func MarshalJSON

func MarshalJSON(v interface{}) ([]byte, error)

func UnmarshalJSON

func UnmarshalJSON(b []byte, typ reflect.Type) (interface{}, error)

Types

type BatchCache

type BatchCache interface {
	ValueType() reflect.Type
	// BatchRead returns values, missed values should be returned as CacheMissed.
	BatchRead(keys *Slice) (*Slice, error)
	BatchWrite(keys *Slice, values *Slice) error
	CanDelete() bool
	Delete(keys *Slice) error
}

type BatchRead

type BatchRead func(keys interface{}) (interface{}, error)

func VariantBatchRead

func VariantBatchRead(fn interface{}) BatchRead

type BatchWrite

type BatchWrite func(keys interface{}, values interface{}) error

func VariantBatchWrite

func VariantBatchWrite(fn interface{}) BatchWrite

type ChainedBatchCache

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

func ChainBatchCache

func ChainBatchCache(upper BatchCache, lowers ...BatchCache) (*ChainedBatchCache, error)

func (*ChainedBatchCache) BatchRead

func (cc *ChainedBatchCache) BatchRead(keys *Slice) (*Slice, error)

func (*ChainedBatchCache) BatchWrite

func (cc *ChainedBatchCache) BatchWrite(keys *Slice, values *Slice) error

func (*ChainedBatchCache) CanDelete

func (cc *ChainedBatchCache) CanDelete() bool

func (*ChainedBatchCache) Delete

func (cc *ChainedBatchCache) Delete(keys *Slice) error

func (*ChainedBatchCache) ValueType

func (cc *ChainedBatchCache) ValueType() reflect.Type

type MapCache

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

func NewMapCache

func NewMapCache(m *sync.Map, valueType reflect.Type) *MapCache

func (*MapCache) BatchRead

func (m *MapCache) BatchRead(keys *Slice) (*Slice, error)

func (*MapCache) BatchWrite

func (m *MapCache) BatchWrite(keys *Slice, values *Slice) error

func (*MapCache) CanDelete

func (m *MapCache) CanDelete() bool

func (*MapCache) Delete

func (m *MapCache) Delete(keys *Slice) error

func (*MapCache) ValueType

func (m *MapCache) ValueType() reflect.Type

type RedisCache

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

func NewRedisCache

func NewRedisCache(pool *redis.Pool, valueType reflect.Type) *RedisCache

func (*RedisCache) BatchRead

func (r *RedisCache) BatchRead(keys *Slice) (*Slice, error)

func (*RedisCache) BatchWrite

func (r *RedisCache) BatchWrite(keys *Slice, values *Slice) error

func (*RedisCache) CanDelete

func (r *RedisCache) CanDelete() bool

func (*RedisCache) Delete

func (r *RedisCache) Delete(keys *Slice) error

func (*RedisCache) ValueType

func (r *RedisCache) ValueType() reflect.Type

func (*RedisCache) WithEX

func (r *RedisCache) WithEX(d time.Duration) *RedisCache

func (*RedisCache) WithNX

func (r *RedisCache) WithNX() *RedisCache

func (*RedisCache) WithValueType

func (r *RedisCache) WithValueType(valueType reflect.Type) *RedisCache

type Slice

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

func NewCacheMissedSlice

func NewCacheMissedSlice(length int, elemType reflect.Type) *Slice

func SliceFromInterfaces

func SliceFromInterfaces(inte []interface{}, elemType reflect.Type) *Slice

func SliceFromReflectValue

func SliceFromReflectValue(value reflect.Value) *Slice

func SliceFromSpecific

func SliceFromSpecific(spec interface{}) *Slice

func (*Slice) Copy

func (s *Slice) Copy() *Slice

func (*Slice) FillMissed

func (s *Slice) FillMissed(data *Slice)

func (*Slice) Filter

func (s *Slice) Filter(indexs []int) *Slice

func (*Slice) Initialized

func (s *Slice) Initialized() bool

func (*Slice) Interfaces

func (s *Slice) Interfaces() []interface{}

func (*Slice) Len

func (s *Slice) Len() int

func (*Slice) Missed

func (s *Slice) Missed() []int

func (*Slice) Specific

func (s *Slice) Specific() interface{}

func (*Slice) SpecificValue

func (s *Slice) SpecificValue() reflect.Value

func (*Slice) String

func (s *Slice) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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