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 Int8
- type Int16
- type Int32
- type Int32CRC
- type Int64
- type Int64CRC
- type IntCRC
- type IsNotFoundFn
- type OpAdd
- type OpCode
- func NewAdd(a RenewDataFn, k any, data any) OpCode
- func NewDelete(d DeleteFn, k any) OpCode
- func NewLoad(l RenewDataFn, k any) OpCode
- func NewMixUpdOrAddIfNull(l RenewDataFn, u UpdateDataFn, a RenewDataFn, i IsNotFoundFn, k any, data any) OpCode
- func NewMixUpsertThenLoad(p UpdateDataFn, l RenewDataFn, k any, data any) OpCode
- func NewMixUpsertThenRenewInCache(p UpdateDataFn, k any, data any) OpCode
- func NewUpdate(l RenewDataFn, u UpdateDataFn, k any, data any) OpCode
- type OpDelete
- type OpLoad
- type OpMixUpdOrAddIfNull
- type OpMixUpsertThenLoad
- type OpMixUpsertThenRenewInCache
- type OpType
- type OpUpdate
- type Option
- type Q
- 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 any, data any) (any, error)
- func (w *Worker) DoDelete(ctx context.Context, deleteFn DeleteFn, k any) (any, error)
- func (w *Worker) DoGet(ctx context.Context, loadFn RenewDataFn, k any) (any, error)
- func (w *Worker) DoUpdOrAddIfNull(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, addFn RenewDataFn, ...) (any, error)
- func (w *Worker) DoUpdate(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, k any, data any) (any, error)
- func (w *Worker) DoUpsertThenLoad(ctx context.Context, upsertFn UpdateDataFn, loadFn RenewDataFn, k any, ...) (any, error)
- func (w *Worker) DoUpsertThenRenewInCache(ctx context.Context, upsertFn UpdateDataFn, k any, data any) (any, 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 any) (any, error)
- func (w *WorkerGrp) DoDelete(ctx context.Context, deleteFn DeleteFn, k Hashed2Int) (any, error)
- func (w *WorkerGrp) DoGet(ctx context.Context, loadFn RenewDataFn, k Hashed2Int) (any, error)
- func (w *WorkerGrp) DoUpdOrAddIfNull(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, addFn RenewDataFn, ...) (any, error)
- func (w *WorkerGrp) DoUpdate(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, k Hashed2Int, ...) (any, error)
- func (w *WorkerGrp) DoUpsertThenLoad(ctx context.Context, upsertFn UpdateDataFn, loadFn RenewDataFn, k Hashed2Int, ...) (any, error)
- func (w *WorkerGrp) DoUpsertThenRenewInCache(ctx context.Context, upsertFn UpdateDataFn, k Hashed2Int, data any) (any, 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 any) (any, bool)
//Get : get from cache, in lru cache, key order also be updated.
Get(key any) (any, bool)
//Set : set to cache
Set(key any, value any)
//Delete : delete key from cache
Delete(key any)
}
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
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() any
}
func NewLoad ¶
func NewLoad(l RenewDataFn, k any) OpCode
func NewMixUpdOrAddIfNull ¶
func NewMixUpdOrAddIfNull(l RenewDataFn, u UpdateDataFn, a RenewDataFn, i IsNotFoundFn, k any, data any) OpCode
func NewMixUpsertThenLoad ¶
func NewMixUpsertThenLoad(p UpdateDataFn, l RenewDataFn, k any, data any) OpCode
func NewMixUpsertThenRenewInCache ¶
func NewMixUpsertThenRenewInCache(p UpdateDataFn, k any, data any) OpCode
func NewUpdate ¶
func NewUpdate(l RenewDataFn, u UpdateDataFn, k any, data any) 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() any
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() any
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() any
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 ¶
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) DoUpdOrAddIfNull ¶
func (w *Worker) DoUpdOrAddIfNull(ctx context.Context, loadFn RenewDataFn, updFn UpdateDataFn, addFn RenewDataFn, isNotFoundFn IsNotFoundFn, k any, data any) (any, 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 any, data any) (any, error)
DoUpdate : update item
func (*Worker) DoUpsertThenLoad ¶
func (w *Worker) DoUpsertThenLoad(ctx context.Context, upsertFn UpdateDataFn, loadFn RenewDataFn, k any, data any) (any, 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 any, data any) (any, 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 any) (any, error)
DoAdd : add item
func (*WorkerGrp) DoGet ¶
func (w *WorkerGrp) DoGet(ctx context.Context, loadFn RenewDataFn, k Hashed2Int) (any, 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 any) (any, 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 any) (any, error)
DoUpdate : update item
func (*WorkerGrp) DoUpsertThenLoad ¶
func (w *WorkerGrp) DoUpsertThenLoad(ctx context.Context, upsertFn UpdateDataFn, loadFn RenewDataFn, k Hashed2Int, data any) (any, 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 any) (any, error)
DoUpsertThenRenewInCache : 1. upsert. 2. update cache if cache hit.