Documentation ¶
Index ¶
- Constants
- Variables
- type AsyncC
- type Byte
- type Bytes
- type CacheFacade
- type CacheGen
- type DeleteFn
- type FacadeLRU
- type FacadeMap
- type Hashed2Int
- type Int
- type Int16
- type Int32
- type Int32CRC
- type Int64
- type Int64CRC
- type Int8
- type IntCRC
- type IsNotFoundFn
- type OpAdd
- type OpCode
- func NewAdd(a RenewDataFn, k interface{}, data interface{}) OpCode
- func NewDelete(d DeleteFn, k interface{}) OpCode
- func NewLoad(l RenewDataFn, k interface{}) OpCode
- func NewMixUpdOrAddIfNull(l RenewDataFn, u UpdateDataFn, a RenewDataFn, i IsNotFoundFn, k interface{}, ...) OpCode
- func NewMixUpsertThenLoad(p UpdateDataFn, l RenewDataFn, k interface{}, data interface{}) OpCode
- func NewMixUpsertThenRenewInCache(p UpdateDataFn, k interface{}, data interface{}) OpCode
- func NewUpdate(l RenewDataFn, u UpdateDataFn, k interface{}, data interface{}) OpCode
- type OpDelete
- type OpLoad
- type OpMixUpdOrAddIfNull
- type OpMixUpsertThenLoad
- type OpMixUpsertThenRenewInCache
- type OpType
- type OpUpdate
- type Option
- type Q
- func (a *Q) AddPriorReq(req interface{}) error
- func (a *Q) AddReq(req interface{}) error
- func (a *Q) AddReqAnyway(req interface{}, ts time.Duration) error
- func (a *Q) Close()
- func (a *Q) IsClosed() bool
- func (a *Q) Pop() (interface{}, error)
- func (a *Q) PopAnyway() (interface{}, error)
- func (a *Q) WaitClose(ctx context.Context) error
- type R
- type RenewDataFn
- type String
- type UInt
- type UInt16
- type UInt32
- type UInt32CRC
- type UInt64
- type UInt64CRC
- type UIntCRC
- type UpdateDataFn
- type Worker
- func (w *Worker) DoAdd(ctx context.Context, addFn RenewDataFn, k interface{}, data interface{}) (interface{}, error)
- func (w *Worker) DoDelete(ctx context.Context, deleteFn DeleteFn, k interface{}) (interface{}, error)
- func (w *Worker) DoGet(ctx context.Context, loadFn RenewDataFn, k interface{}) (interface{}, error)
- func (w *Worker) DoUpdOrAddIfNull(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, addFn RenewDataFn, ...) (interface{}, error)
- func (w *Worker) DoUpdate(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, k interface{}, ...) (interface{}, error)
- func (w *Worker) DoUpsertThenLoad(ctx context.Context, upsertFn UpdateDataFn, loadFn RenewDataFn, k interface{}, ...) (interface{}, error)
- func (w *Worker) DoUpsertThenRenewInCache(ctx context.Context, upsertFn UpdateDataFn, k interface{}, data interface{}) (interface{}, error)
- func (w *Worker) Start()
- func (w *Worker) Stop()
- type WorkerGrp
- func (w *WorkerGrp) DeepSize() int
- func (w *WorkerGrp) DoAdd(ctx context.Context, addFn RenewDataFn, k Hashed2Int, data interface{}) (interface{}, error)
- func (w *WorkerGrp) DoDelete(ctx context.Context, deleteFn DeleteFn, k Hashed2Int) (interface{}, error)
- func (w *WorkerGrp) DoGet(ctx context.Context, loadFn RenewDataFn, k Hashed2Int) (interface{}, error)
- func (w *WorkerGrp) DoUpdOrAddIfNull(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, addFn RenewDataFn, ...) (interface{}, error)
- func (w *WorkerGrp) DoUpdate(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, k Hashed2Int, ...) (interface{}, error)
- func (w *WorkerGrp) DoUpsertThenLoad(ctx context.Context, upsertFn UpdateDataFn, loadFn RenewDataFn, k Hashed2Int, ...) (interface{}, error)
- func (w *WorkerGrp) DoUpsertThenRenewInCache(ctx context.Context, upsertFn UpdateDataFn, k Hashed2Int, data interface{}) (interface{}, error)
- func (w *WorkerGrp) MuxSize() int
- func (w *WorkerGrp) Start()
- func (w *WorkerGrp) Stop()
- func (w *WorkerGrp) WaitStop(ctx context.Context) error
Constants ¶
const ( //DefaultMuxSize slot size //素数 DefaultMuxSize = 127 //DefaultDeepSize default queue deep DefaultDeepSize = 1024 * 8 )
Variables ¶
var ( //ErrClosed close ErrClosed = status.Error(codes.Unavailable, "q.closed") //ErrQFull req q full ErrQFull = status.Error(codes.ResourceExhausted, "q.full") //ErrSync never gonna happen ErrSync = errors.New("never.gonna.happen.crazy") )
var (
ErrDupKey = status.Error(codes.AlreadyExists, "gas.duplicated.key")
)
Functions ¶
This section is empty.
Types ¶
type CacheFacade ¶
type CacheFacade interface { //Peek : only useful in lru cache, peek means no update LRU order. Peek(key interface{}) (interface{}, bool) //Get : get from cache, in lru cache, key order also be updated. Get(key interface{}) (interface{}, bool) //Set : set to cache Set(key interface{}, value interface{}) //Delete : delete key from cache Delete(key interface{}) }
CacheFacade : cache facade, could be lru cache, map, or both mixed.
func NewFacadeLRU ¶
func NewFacadeLRU(capacity int64) CacheFacade
NewFacadeLRU : creates a new empty cache with the given capacity.
func NewFacadeMap ¶
func NewFacadeMap() CacheFacade
type DeleteFn ¶
DeleteFn : delete data function. input: ctx->context:can be ignored in case; d->input data. output: error->if failed, return err.
type FacadeLRU ¶
FacadeLRU : extend LRUCache to interface CacheFacade
func (*FacadeLRU) Delete ¶
func (m *FacadeLRU) Delete(key interface{})
Delete : delete key from cache
type Hashed2Int ¶
type Hashed2Int interface { //HashedInt : the hashed int HashedInt() int }
Hashed2Int : can be hashed to int
type IsNotFoundFn ¶
IsNotFoundFn : to detective an error is "not found" or not.
type OpAdd ¶
type OpAdd struct {
// contains filtered or unexported fields
}
OpAdd : wrapped add command
type OpCode ¶
type OpCode interface {
GetK() interface{}
}
func NewAdd ¶
func NewAdd(a RenewDataFn, k interface{}, data interface{}) OpCode
func NewLoad ¶
func NewLoad(l RenewDataFn, k interface{}) OpCode
func NewMixUpdOrAddIfNull ¶
func NewMixUpdOrAddIfNull(l RenewDataFn, u UpdateDataFn, a RenewDataFn, i IsNotFoundFn, k interface{}, data interface{}) OpCode
func NewMixUpsertThenLoad ¶
func NewMixUpsertThenLoad(p UpdateDataFn, l RenewDataFn, k interface{}, data interface{}) OpCode
func NewMixUpsertThenRenewInCache ¶
func NewMixUpsertThenRenewInCache(p UpdateDataFn, k interface{}, data interface{}) OpCode
func NewUpdate ¶
func NewUpdate(l RenewDataFn, u UpdateDataFn, k interface{}, data interface{}) OpCode
type OpDelete ¶
type OpDelete struct {
// contains filtered or unexported fields
}
OpDelete : wrapped delete command
type OpLoad ¶
type OpLoad struct {
// contains filtered or unexported fields
}
OpLoad : wrapped load command
type OpMixUpdOrAddIfNull ¶
type OpMixUpdOrAddIfNull struct {
// contains filtered or unexported fields
}
OpMixUpdOrAddIfNull : 1.load. 2. update it if existed. 3. add it if not existed.
load; if not found -> add. else update.
func (*OpMixUpdOrAddIfNull) GetK ¶
func (o *OpMixUpdOrAddIfNull) GetK() interface{}
type OpMixUpsertThenLoad ¶
type OpMixUpsertThenLoad struct {
// contains filtered or unexported fields
}
OpMixUpsertThenLoad : upsert it first, then load it if not in cache.
1. upsert. 2. if in cache, refresh cache. 3. if not in cache, reload from cache.
func (*OpMixUpsertThenLoad) GetK ¶
func (o *OpMixUpsertThenLoad) GetK() interface{}
type OpMixUpsertThenRenewInCache ¶
type OpMixUpsertThenRenewInCache struct {
// contains filtered or unexported fields
}
OpMixUpsertThenRenewInCache : upsert it first, then renew in cache item.
1. upsert. 2. if in cache, renew cache. 3. if not in cache, do nothing.
func (*OpMixUpsertThenRenewInCache) GetK ¶
func (o *OpMixUpsertThenRenewInCache) GetK() interface{}
type OpUpdate ¶
type OpUpdate struct {
// contains filtered or unexported fields
}
OpUpdate : wrapped update command Actually : update should after load data
type Q ¶
type Q struct {
// contains filtered or unexported fields
}
Q actor queue structure define
func (*Q) AddPriorReq ¶
AddPriorReq add normal request to the normal queue first place.
func (*Q) AddReqAnyway ¶
AddReqAnyway add normal request to the normal queue end place anyway if queue full, sleep then try
type R ¶
type R struct {
// contains filtered or unexported fields
}
R : combine interface and error, for return result
type RenewDataFn ¶
RenewDataFn : renew data function, including load/add, excluding delete. input: ctx->context:can be ignored in case; d->input data output: v-> return cache value; err->if failed, return err
type UpdateDataFn ¶
type UpdateDataFn func(ctx context.Context, d interface{}, e interface{}) (v interface{}, err error)
UpdateDataFn : update data function. input: ctx->context:can be ignored in case; d->input data; e->the existed item. output: v-> return cache value; err->if failed, return err. actually e is from load function if it's not in cache.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker : a go routine to handle queue work
func (*Worker) DoAdd ¶
func (w *Worker) DoAdd(ctx context.Context, addFn RenewDataFn, k interface{}, data interface{}) (interface{}, error)
DoAdd : add item
func (*Worker) DoDelete ¶
func (w *Worker) DoDelete(ctx context.Context, deleteFn DeleteFn, k interface{}) (interface{}, error)
DoDelete : delete item
func (*Worker) DoGet ¶
func (w *Worker) DoGet(ctx context.Context, loadFn RenewDataFn, k interface{}) (interface{}, error)
DoGet : get from cache first if not load from db
func (*Worker) DoUpdOrAddIfNull ¶
func (w *Worker) DoUpdOrAddIfNull(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, addFn RenewDataFn, isNotFoundFn IsNotFoundFn, k interface{}, data interface{}) (interface{}, error)
DoUpdOrAddIfNull : 1. load. 2. update if existed. 3. add if not existed.
func (*Worker) DoUpdate ¶
func (w *Worker) DoUpdate(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, k interface{}, data interface{}) (interface{}, error)
DoUpdate : update item
func (*Worker) DoUpsertThenLoad ¶
func (w *Worker) DoUpsertThenLoad(ctx context.Context, upsertFn UpdateDataFn, loadFn RenewDataFn, k interface{}, data interface{}) (interface{}, error)
DoUpsertThenLoad : 1. upsert. 2. update cache if cache hit. 3. load cache if cache miss.
func (*Worker) DoUpsertThenRenewInCache ¶
func (w *Worker) DoUpsertThenRenewInCache(ctx context.Context, upsertFn UpdateDataFn, k interface{}, data interface{}) (interface{}, error)
DoUpsertThenRenewInCache : 1. upsert. 2. update cache if cache hit.
type WorkerGrp ¶
type WorkerGrp struct {
// contains filtered or unexported fields
}
WorkerGrp : worker group
func NewWorkGrp ¶
NewWorkGrp : new work group
func NewWorkGrpWithLRU ¶
NewWorkGrpWithLRU : new work group bind with lru cache.
func NewWorkGrpWithMapCache ¶
NewWorkGrpWithMapCache : new work group bind with map cache.
func (*WorkerGrp) DoAdd ¶
func (w *WorkerGrp) DoAdd(ctx context.Context, addFn RenewDataFn, k Hashed2Int, data interface{}) (interface{}, error)
DoAdd : add item
func (*WorkerGrp) DoDelete ¶
func (w *WorkerGrp) DoDelete(ctx context.Context, deleteFn DeleteFn, k Hashed2Int) (interface{}, error)
DoDelete : delete item
func (*WorkerGrp) DoGet ¶
func (w *WorkerGrp) DoGet(ctx context.Context, loadFn RenewDataFn, k Hashed2Int) (interface{}, error)
DoGet : get from cache first if not load from db
func (*WorkerGrp) DoUpdOrAddIfNull ¶
func (w *WorkerGrp) DoUpdOrAddIfNull(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, addFn RenewDataFn, isNotFoundFn IsNotFoundFn, k Hashed2Int, data interface{}) (interface{}, error)
DoUpdOrAddIfNull : 1. load. 2. update if existed. 3. add if not existed.
func (*WorkerGrp) DoUpdate ¶
func (w *WorkerGrp) DoUpdate(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, k Hashed2Int, data interface{}) (interface{}, error)
DoUpdate : update item
func (*WorkerGrp) DoUpsertThenLoad ¶
func (w *WorkerGrp) DoUpsertThenLoad(ctx context.Context, upsertFn UpdateDataFn, loadFn RenewDataFn, k Hashed2Int, data interface{}) (interface{}, error)
DoUpsertThenLoad : 1. upsert. 2. update cache if cache hit. 3. load cache if cache miss.
func (*WorkerGrp) DoUpsertThenRenewInCache ¶
func (w *WorkerGrp) DoUpsertThenRenewInCache(ctx context.Context, upsertFn UpdateDataFn, k Hashed2Int, data interface{}) (interface{}, error)
DoUpsertThenRenewInCache : 1. upsert. 2. update cache if cache hit.